UNPKG

ky

Version:

Tiny and elegant HTTP client based on the Fetch API

28 lines (26 loc) • 905 B
import { KyError } from './KyError.js'; /** Error thrown when the response body exceeds `maxResponseSize`. It has a `request` property with the `Request` object and a `maxResponseSize` property with the configured limit in bytes. @example ``` import ky, {isResponseSizeError} from 'ky'; try { await ky('https://example.com/data', {maxResponseSize: 1024}).json(); } catch (error) { if (isResponseSizeError(error)) { console.log(`Response exceeded ${error.maxResponseSize} bytes`); } } ``` */ export class ResponseSizeError extends KyError { name = 'ResponseSizeError'; request; maxResponseSize; constructor(request, maxResponseSize) { super(`Response body exceeded ${maxResponseSize} bytes: ${request.method} ${request.url}`); this.request = request; this.maxResponseSize = maxResponseSize; } } //# sourceMappingURL=ResponseSizeError.js.map