got 11.8.2 → 11.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  import { ResponseType, Response, ParseJsonFunction } from './types';
2
- declare const parseBody: (response: Response, responseType: ResponseType, parseJson: ParseJsonFunction, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined) => unknown;
2
+ declare const parseBody: (response: Response, responseType: ResponseType, parseJson: ParseJsonFunction, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex" | undefined) => unknown;
3
3
  export default parseBody;
@@ -21,6 +21,7 @@ class ParseError extends core_1.RequestError {
21
21
  const { options } = response.request;
22
22
  super(`${error.message} in "${options.url.toString()}"`, error, response.request);
23
23
  this.name = 'ParseError';
24
+ this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_BODY_PARSE_FAILURE' : this.code;
24
25
  }
25
26
  }
26
27
  exports.ParseError = ParseError;
@@ -31,6 +32,7 @@ class CancelError extends core_1.RequestError {
31
32
  constructor(request) {
32
33
  super('Promise was canceled', {}, request);
33
34
  this.name = 'CancelError';
35
+ this.code = 'ERR_CANCELED';
34
36
  }
35
37
  get isCanceled() {
36
38
  return true;
@@ -952,7 +952,7 @@ An error to be thrown when a request fails.
952
952
  Contains a `code` property with error class code, like `ECONNREFUSED`.
953
953
  */
954
954
  export declare class RequestError extends Error {
955
- code?: string;
955
+ code: string;
956
956
  stack: string;
957
957
  readonly options: NormalizedOptions;
958
958
  readonly response?: Response;
@@ -121,11 +121,11 @@ Contains a `code` property with error class code, like `ECONNREFUSED`.
121
121
  */
122
122
  class RequestError extends Error {
123
123
  constructor(message, error, self) {
124
- var _a;
124
+ var _a, _b;
125
125
  super(message);
126
126
  Error.captureStackTrace(this, this.constructor);
127
127
  this.name = 'RequestError';
128
- this.code = error.code;
128
+ this.code = (_a = error.code) !== null && _a !== void 0 ? _a : 'ERR_GOT_REQUEST_ERROR';
129
129
  if (self instanceof Request) {
130
130
  Object.defineProperty(this, 'request', {
131
131
  enumerable: false,
@@ -150,7 +150,7 @@ class RequestError extends Error {
150
150
  value: self
151
151
  });
152
152
  }
153
- this.timings = (_a = this.request) === null || _a === void 0 ? void 0 : _a.timings;
153
+ this.timings = (_b = this.request) === null || _b === void 0 ? void 0 : _b.timings;
154
154
  // Recover the original stacktrace
155
155
  if (is_1.default.string(error.stack) && is_1.default.string(this.stack)) {
156
156
  const indexOfMessage = this.stack.indexOf(this.message) + this.message.length;
@@ -173,6 +173,7 @@ class MaxRedirectsError extends RequestError {
173
173
  constructor(request) {
174
174
  super(`Redirected ${request.options.maxRedirects} times. Aborting.`, {}, request);
175
175
  this.name = 'MaxRedirectsError';
176
+ this.code = 'ERR_TOO_MANY_REDIRECTS';
176
177
  }
177
178
  }
178
179
  exports.MaxRedirectsError = MaxRedirectsError;
@@ -184,6 +185,7 @@ class HTTPError extends RequestError {
184
185
  constructor(response) {
185
186
  super(`Response code ${response.statusCode} (${response.statusMessage})`, {}, response.request);
186
187
  this.name = 'HTTPError';
188
+ this.code = 'ERR_NON_2XX_3XX_RESPONSE';
187
189
  }
188
190
  }
189
191
  exports.HTTPError = HTTPError;
@@ -195,6 +197,7 @@ class CacheError extends RequestError {
195
197
  constructor(error, request) {
196
198
  super(error.message, error, request);
197
199
  this.name = 'CacheError';
200
+ this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_CACHE_ACCESS' : this.code;
198
201
  }
199
202
  }
200
203
  exports.CacheError = CacheError;
@@ -205,6 +208,7 @@ class UploadError extends RequestError {
205
208
  constructor(error, request) {
206
209
  super(error.message, error, request);
207
210
  this.name = 'UploadError';
211
+ this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_UPLOAD' : this.code;
208
212
  }
209
213
  }
210
214
  exports.UploadError = UploadError;
@@ -228,6 +232,7 @@ class ReadError extends RequestError {
228
232
  constructor(error, request) {
229
233
  super(error.message, error, request);
230
234
  this.name = 'ReadError';
235
+ this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_READING_RESPONSE_STREAM' : this.code;
231
236
  }
232
237
  }
233
238
  exports.ReadError = ReadError;
@@ -238,6 +243,7 @@ class UnsupportedProtocolError extends RequestError {
238
243
  constructor(options) {
239
244
  super(`Unsupported protocol "${options.url.protocol}"`, {}, options);
240
245
  this.name = 'UnsupportedProtocolError';
246
+ this.code = 'ERR_UNSUPPORTED_PROTOCOL';
241
247
  }
242
248
  }
243
249
  exports.UnsupportedProtocolError = UnsupportedProtocolError;
@@ -226,49 +226,51 @@ export interface Got extends Record<HTTPAlias, GotRequestFunction>, GotRequestFu
226
226
  */
227
227
  defaults: InstanceDefaults;
228
228
  /**
229
- An error to be thrown when a cache method fails.
230
- For example, if the database goes down or there's a filesystem error.
229
+ An error to be thrown when a cache method fails. For example, if the database goes down or there's a filesystem error.
230
+ Contains a `code` property with `ERR_CACHE_ACCESS` or a more specific failure code.
231
231
  */
232
232
  CacheError: typeof CacheError;
233
233
  /**
234
- An error to be thrown when a request fails.
235
- Contains a `code` property with error class code, like `ECONNREFUSED`.
234
+ An error to be thrown when a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`.
235
+ If there is no specific code supplied, `code` defaults to `ERR_GOT_REQUEST_ERROR`.
236
236
  */
237
237
  RequestError: typeof RequestError;
238
238
  /**
239
- An error to be thrown when reading from response stream fails.
239
+ An error to be thrown when reading from response stream fails. Contains a `code` property with
240
+ `ERR_READING_RESPONSE_STREAM` or a more specific failure code.
240
241
  */
241
242
  ReadError: typeof ReadError;
242
243
  /**
243
- An error to be thrown when server response code is 2xx, and parsing body fails.
244
- Includes a `response` property.
244
+ An error to be thrown when server response code is 2xx, and parsing body fails. Includes a
245
+ `response` property. Contains a `code` property with `ERR_BODY_PARSE_FAILURE` or a more specific failure code.
245
246
  */
246
247
  ParseError: typeof ParseError;
247
248
  /**
248
249
  An error to be thrown when the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304.
249
- Includes a `response` property.
250
+ Includes a `response` property. Contains a `code` property with `ERR_NON_2XX_3XX_RESPONSE` or a more specific failure code.
250
251
  */
251
252
  HTTPError: typeof HTTPError;
252
253
  /**
253
254
  An error to be thrown when the server redirects you more than ten times.
254
- Includes a `response` property.
255
+ Includes a `response` property. Contains a `code` property with `ERR_TOO_MANY_REDIRECTS`.
255
256
  */
256
257
  MaxRedirectsError: typeof MaxRedirectsError;
257
258
  /**
258
- An error to be thrown when given an unsupported protocol.
259
+ An error to be thrown when given an unsupported protocol. Contains a `code` property with `ERR_UNSUPPORTED_PROTOCOL`.
259
260
  */
260
261
  UnsupportedProtocolError: typeof UnsupportedProtocolError;
261
262
  /**
262
263
  An error to be thrown when the request is aborted due to a timeout.
263
- Includes an `event` and `timings` property.
264
+ Includes an `event` and `timings` property. Contains a `code` property with `ETIMEDOUT`.
264
265
  */
265
266
  TimeoutError: typeof TimeoutError;
266
267
  /**
267
268
  An error to be thrown when the request body is a stream and an error occurs while reading from that stream.
269
+ Contains a `code` property with `ERR_UPLOAD` or a more specific failure code.
268
270
  */
269
271
  UploadError: typeof UploadError;
270
272
  /**
271
- An error to be thrown when the request is aborted with `.cancel()`.
273
+ An error to be thrown when the request is aborted with `.cancel()`. Contains a `code` property with `ERR_CANCELED`.
272
274
  */
273
275
  CancelError: typeof CancelError;
274
276
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "11.8.2",
3
+ "version": "11.8.3",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",
@@ -48,7 +48,7 @@
48
48
  "@types/cacheable-request": "^6.0.1",
49
49
  "@types/responselike": "^1.0.0",
50
50
  "cacheable-lookup": "^5.0.3",
51
- "cacheable-request": "^7.0.1",
51
+ "cacheable-request": "^7.0.2",
52
52
  "decompress-response": "^6.0.0",
53
53
  "http2-wrapper": "^1.0.0-beta.5.2",
54
54
  "lowercase-keys": "^2.0.0",
package/readme.md CHANGED
@@ -1705,43 +1705,44 @@ Additionaly, the errors may have `request` (Got Stream) and `response` (Got Resp
1705
1705
 
1706
1706
  #### got.RequestError
1707
1707
 
1708
- When a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`. All the errors below inherit this one.
1708
+ When a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`. If there is no specific code supplied, `code` defaults to `ERR_GOT_REQUEST_ERROR`. All the errors below inherit this one.
1709
1709
 
1710
1710
  #### got.CacheError
1711
1711
 
1712
- When a cache method fails, for example, if the database goes down or there's a filesystem error.
1712
+ When a cache method fails, for example, if the database goes down or there's a filesystem error. Contains a `code` property with `ERR_CACHE_ACCESS` or a more specific failure code.
1713
1713
 
1714
1714
  #### got.ReadError
1715
1715
 
1716
- When reading from response stream fails.
1716
+ When reading from response stream fails. Contains a `code` property with `ERR_READING_RESPONSE_STREAM` or a more specific failure code.
1717
1717
 
1718
1718
  #### got.ParseError
1719
1719
 
1720
- When server response code is 2xx, and parsing body fails. Includes a `response` property.
1720
+ When server response code is 2xx, and parsing body fails. Includes a `response` property. Contains a `code` property with `ERR_BODY_PARSE_FAILURE` or a more specific failure code.
1721
1721
 
1722
1722
  #### got.UploadError
1723
1723
 
1724
- When the request body is a stream and an error occurs while reading from that stream.
1724
+ When the request body is a stream and an error occurs while reading from that stream. Contains a `code` property with `ERR_UPLOAD` or a more specific failure code.
1725
1725
 
1726
1726
  #### got.HTTPError
1727
1727
 
1728
- When the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304. Includes a `response` property.
1728
+ When the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304. Includes a `response` property. Contains a `code` property with `ERR_NON_2XX_3XX_RESPONSE` or a more specific failure code.
1729
+
1729
1730
 
1730
1731
  #### got.MaxRedirectsError
1731
1732
 
1732
- When the server redirects you more than ten times. Includes a `response` property.
1733
+ When the server redirects you more than ten times. Includes a `response` property. Contains a `code` property with `ERR_TOO_MANY_REDIRECTS`.
1733
1734
 
1734
1735
  #### got.UnsupportedProtocolError
1735
1736
 
1736
- When given an unsupported protocol.
1737
+ When given an unsupported protocol. Contains a `code` property with `ERR_UNSUPPORTED_PROTOCOL`.
1737
1738
 
1738
1739
  #### got.TimeoutError
1739
1740
 
1740
- When the request is aborted due to a [timeout](#timeout). Includes an `event` and `timings` property.
1741
+ When the request is aborted due to a [timeout](#timeout). Includes an `event` and `timings` property. Contains a `code` property with `ETIMEDOUT`.
1741
1742
 
1742
1743
  #### got.CancelError
1743
1744
 
1744
- When the request is aborted with `.cancel()`.
1745
+ When the request is aborted with `.cancel()`. Contains a `code` property with `ERR_CANCELED`.
1745
1746
 
1746
1747
  ## Aborting the request
1747
1748