got 11.7.0 → 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.
@@ -133,9 +133,10 @@ function asPromise(normalizedOptions) {
133
133
  reject(error);
134
134
  };
135
135
  request.once('error', onError);
136
+ const previousBody = request.options.body;
136
137
  request.once('retry', (newRetryCount, error) => {
137
- var _a;
138
- if (is_1.default.nodeStream((_a = error.request) === null || _a === void 0 ? void 0 : _a.options.body)) {
138
+ var _a, _b;
139
+ if (previousBody === ((_a = error.request) === null || _a === void 0 ? void 0 : _a.options.body) && is_1.default.nodeStream((_b = error.request) === null || _b === void 0 ? void 0 : _b.options.body)) {
139
140
  onError(error);
140
141
  return;
141
142
  }
@@ -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;
@@ -41,12 +41,8 @@ export interface Agents {
41
41
  }
42
42
  export declare const withoutBody: ReadonlySet<string>;
43
43
  export interface ToughCookieJar {
44
- getCookieString: ((currentUrl: string, options: {
45
- [key: string]: unknown;
46
- }, cb: (err: Error | null, cookies: string) => void) => void) & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void);
47
- setCookie: ((cookieOrString: unknown, currentUrl: string, options: {
48
- [key: string]: unknown;
49
- }, cb: (err: Error | null, cookie: unknown) => void) => void) & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void);
44
+ getCookieString: ((currentUrl: string, options: Record<string, unknown>, cb: (err: Error | null, cookies: string) => void) => void) & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void);
45
+ setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, cb: (err: Error | null, cookie: unknown) => void) => void) & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void);
50
46
  }
51
47
  export interface PromiseCookieJar {
52
48
  getCookieString: (url: string) => Promise<string>;
@@ -352,9 +348,7 @@ interface PlainOptions extends URLOptions {
352
348
 
353
349
  __Note #2__: This option is not enumerable and will not be merged with the instance defaults.
354
350
  */
355
- form?: {
356
- [key: string]: any;
357
- };
351
+ form?: Record<string, any>;
358
352
  /**
359
353
  JSON body. If the `Content-Type` header is not set, it will be set to `application/json`.
360
354
 
@@ -362,9 +356,7 @@ interface PlainOptions extends URLOptions {
362
356
 
363
357
  __Note #2__: This option is not enumerable and will not be merged with the instance defaults.
364
358
  */
365
- json?: {
366
- [key: string]: any;
367
- };
359
+ json?: Record<string, any>;
368
360
  /**
369
361
  The URL to request, as a string, a [`https.request` options object](https://nodejs.org/api/https.html#https_https_request_options_callback), or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
370
362
 
@@ -415,9 +407,7 @@ interface PlainOptions extends URLOptions {
415
407
  //=> 'key=a&key=b'
416
408
  ```
417
409
  */
418
- searchParams?: string | {
419
- [key: string]: string | number | boolean | null | undefined;
420
- } | URLSearchParams;
410
+ searchParams?: string | Record<string, string | number | boolean | null | undefined> | URLSearchParams;
421
411
  /**
422
412
  An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups.
423
413
  Useful when making lots of requests to different *public* hostnames.
@@ -962,7 +952,7 @@ An error to be thrown when a request fails.
962
952
  Contains a `code` property with error class code, like `ECONNREFUSED`.
963
953
  */
964
954
  export declare class RequestError extends Error {
965
- code?: string;
955
+ code: string;
966
956
  stack: string;
967
957
  readonly options: NormalizedOptions;
968
958
  readonly response?: Response;
@@ -29,7 +29,7 @@ const is_response_ok_1 = require("./utils/is-response-ok");
29
29
  const deprecation_warning_1 = require("../utils/deprecation-warning");
30
30
  const normalize_arguments_1 = require("../as-promise/normalize-arguments");
31
31
  const calculate_retry_delay_1 = require("./calculate-retry-delay");
32
- const globalDnsCache = new cacheable_lookup_1.default();
32
+ let globalDnsCache;
33
33
  const kRequest = Symbol('request');
34
34
  const kResponse = Symbol('response');
35
35
  const kResponseSize = Symbol('responseSize');
@@ -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,9 +150,9 @@ 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
- if (!is_1.default.undefined(error.stack)) {
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;
157
157
  const thisStackTrace = this.stack.slice(indexOfMessage).split('\n').reverse();
158
158
  const errorStackTrace = error.stack.slice(error.stack.indexOf(error.message) + error.message.length).split('\n').reverse();
@@ -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;
@@ -586,6 +592,9 @@ class Request extends stream_1.Duplex {
586
592
  options.cacheOptions = { ...options.cacheOptions };
587
593
  // `options.dnsCache`
588
594
  if (options.dnsCache === true) {
595
+ if (!globalDnsCache) {
596
+ globalDnsCache = new cacheable_lookup_1.default();
597
+ }
589
598
  options.dnsCache = globalDnsCache;
590
599
  }
591
600
  else if (!is_1.default.undefined(options.dnsCache) && !options.dnsCache.lookup) {
@@ -628,7 +637,7 @@ class Request extends stream_1.Duplex {
628
637
  if (defaults && !areHooksDefault) {
629
638
  for (const event of exports.knownHookEvents) {
630
639
  const defaultHooks = defaults.hooks[event];
631
- if (defaultHooks.length !== 0) {
640
+ if (defaultHooks.length > 0) {
632
641
  // See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
633
642
  options.hooks[event] = [
634
643
  ...defaults.hooks[event],
@@ -950,12 +959,7 @@ class Request extends stream_1.Duplex {
950
959
  request.destroy();
951
960
  // Node.js <= 12.18.2 mistakenly emits the response `end` first.
952
961
  (_a = request.res) === null || _a === void 0 ? void 0 : _a.removeAllListeners('end');
953
- if (error instanceof timed_out_1.TimeoutError) {
954
- error = new TimeoutError(error, this.timings, this);
955
- }
956
- else {
957
- error = new RequestError(error.message, error, this);
958
- }
962
+ error = error instanceof timed_out_1.TimeoutError ? new TimeoutError(error, this.timings, this) : new RequestError(error.message, error, this);
959
963
  this._beforeError(error);
960
964
  });
961
965
  this[kUnproxyEvents] = proxy_events_1.default(request, this, proxiedRequestEvents);
@@ -1319,7 +1323,7 @@ class Request extends stream_1.Duplex {
1319
1323
  });
1320
1324
  // TODO: What happens if it's from cache? Then this[kRequest] won't be defined.
1321
1325
  this[kRequest].write(chunk, encoding, (error) => {
1322
- if (!error && this._progressCallbacks.length !== 0) {
1326
+ if (!error && this._progressCallbacks.length > 0) {
1323
1327
  this._progressCallbacks.shift()();
1324
1328
  }
1325
1329
  callback(error);
@@ -1383,7 +1387,7 @@ class Request extends stream_1.Duplex {
1383
1387
  */
1384
1388
  get ip() {
1385
1389
  var _a;
1386
- return (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket.remoteAddress;
1390
+ return (_a = this.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress;
1387
1391
  }
1388
1392
  /**
1389
1393
  Indicates whether the request has been aborted or not.
@@ -1393,8 +1397,8 @@ class Request extends stream_1.Duplex {
1393
1397
  return ((_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.destroyed) !== null && _b !== void 0 ? _b : this.destroyed) && !((_c = this[kOriginalResponse]) === null || _c === void 0 ? void 0 : _c.complete);
1394
1398
  }
1395
1399
  get socket() {
1396
- var _a;
1397
- return (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket;
1400
+ var _a, _b;
1401
+ return (_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket) !== null && _b !== void 0 ? _b : undefined;
1398
1402
  }
1399
1403
  /**
1400
1404
  Progress event for downloading (receiving a response).
@@ -23,6 +23,9 @@ exports.default = async (body, headers) => {
23
23
  }
24
24
  if (body instanceof fs_1.ReadStream) {
25
25
  const { size } = await statAsync(body.path);
26
+ if (size === 0) {
27
+ return undefined;
28
+ }
26
29
  return size;
27
30
  }
28
31
  return undefined;
@@ -14,7 +14,7 @@ exports.default = (url) => {
14
14
  href: url.href,
15
15
  path: `${url.pathname || ''}${url.search || ''}`
16
16
  };
17
- if (is_1.default.string(url.port) && url.port.length !== 0) {
17
+ if (is_1.default.string(url.port) && url.port.length > 0) {
18
18
  options.port = Number(url.port);
19
19
  }
20
20
  if (url.username || url.password) {
@@ -82,7 +82,7 @@ const create = (defaults) => {
82
82
  return result;
83
83
  }));
84
84
  // Got interface
85
- const got = ((url, options, _defaults) => {
85
+ const got = ((url, options = {}, _defaults) => {
86
86
  var _a, _b;
87
87
  let iteration = 0;
88
88
  const iterateHandlers = (newOptions) => {
@@ -103,7 +103,7 @@ const create = (defaults) => {
103
103
  let initHookError;
104
104
  try {
105
105
  callInitHooks(defaults.options.hooks.init, options);
106
- callInitHooks((_a = options === null || options === void 0 ? void 0 : options.hooks) === null || _a === void 0 ? void 0 : _a.init, options);
106
+ callInitHooks((_a = options.hooks) === null || _a === void 0 ? void 0 : _a.init, options);
107
107
  }
108
108
  catch (error) {
109
109
  initHookError = error;
@@ -117,11 +117,11 @@ const create = (defaults) => {
117
117
  return iterateHandlers(normalizedOptions);
118
118
  }
119
119
  catch (error) {
120
- if (options === null || options === void 0 ? void 0 : options.isStream) {
120
+ if (options.isStream) {
121
121
  throw error;
122
122
  }
123
123
  else {
124
- return create_rejection_1.default(error, defaults.options.hooks.beforeError, (_b = options === null || options === void 0 ? void 0 : options.hooks) === null || _b === void 0 ? void 0 : _b.beforeError);
124
+ return create_rejection_1.default(error, defaults.options.hooks.beforeError, (_b = options.hooks) === null || _b === void 0 ? void 0 : _b.beforeError);
125
125
  }
126
126
  }
127
127
  });
@@ -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.7.0",
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",
@@ -43,12 +43,12 @@
43
43
  "ky"
44
44
  ],
45
45
  "dependencies": {
46
- "@sindresorhus/is": "^3.1.1",
46
+ "@sindresorhus/is": "^4.0.0",
47
47
  "@szmarczak/http-timer": "^4.0.5",
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",
@@ -61,7 +61,7 @@
61
61
  "@sinonjs/fake-timers": "^6.0.1",
62
62
  "@types/benchmark": "^1.0.33",
63
63
  "@types/express": "^4.17.7",
64
- "@types/node": "^14.6.0",
64
+ "@types/node": "^14.14.0",
65
65
  "@types/node-fetch": "^2.5.7",
66
66
  "@types/pem": "^1.9.5",
67
67
  "@types/pify": "^3.0.2",
@@ -87,11 +87,11 @@
87
87
  "pify": "^5.0.0",
88
88
  "sinon": "^9.0.3",
89
89
  "slow-stream": "0.0.4",
90
- "tempy": "^0.6.0",
90
+ "tempy": "^1.0.0",
91
91
  "to-readable-stream": "^2.1.0",
92
92
  "tough-cookie": "^4.0.0",
93
- "typescript": "^4.0.2",
94
- "xo": "^0.33.0"
93
+ "typescript": "4.0.3",
94
+ "xo": "^0.34.1"
95
95
  },
96
96
  "types": "dist/source",
97
97
  "sideEffects": false,
@@ -123,7 +123,7 @@
123
123
  "node/prefer-global/url": "off",
124
124
  "node/prefer-global/url-search-params": "off",
125
125
  "import/no-anonymous-default-export": "off",
126
- "@typescript-eslint/no-invalid-void-type": "off"
126
+ "@typescript-eslint/no-implicit-any-catch": "off"
127
127
  }
128
128
  },
129
129
  "runkitExampleFilename": "./documentation/examples/runkit-example.js"
package/readme.md CHANGED
@@ -107,16 +107,16 @@ const got = require('got');
107
107
  const pipeline = promisify(stream.pipeline);
108
108
 
109
109
  (async () => {
110
- await pipeline(
111
- got.stream('https://sindresorhus.com'),
112
- fs.createWriteStream('index.html')
113
- );
114
-
115
- // For POST, PUT, and PATCH methods `got.stream` returns a `stream.Writable`
116
- await pipeline(
117
- fs.createReadStream('index.html'),
118
- got.stream.post('https://sindresorhus.com')
119
- );
110
+ await pipeline(
111
+ got.stream('https://sindresorhus.com'),
112
+ fs.createWriteStream('index.html')
113
+ );
114
+
115
+ // For POST, PUT, PATCH, and DELETE methods, `got.stream` returns a `stream.Writable`.
116
+ await pipeline(
117
+ fs.createReadStream('index.html'),
118
+ got.stream.post('https://sindresorhus.com')
119
+ );
120
120
  })();
121
121
  ```
122
122
 
@@ -306,7 +306,7 @@ Example:
306
306
  const bufferPromise = responsePromise.buffer();
307
307
  const jsonPromise = responsePromise.json();
308
308
 
309
- const [response, buffer, json] = Promise.all([responsePromise, bufferPromise, jsonPromise]);
309
+ const [response, buffer, json] = await Promise.all([responsePromise, bufferPromise, jsonPromise]);
310
310
  // `response` is an instance of Got Response
311
311
  // `buffer` is an instance of Buffer
312
312
  // `json` is an object
@@ -655,6 +655,15 @@ await got('https://api6.ipify.org', {
655
655
  });
656
656
  ```
657
657
 
658
+ ###### lookup
659
+
660
+ Type: `Function`\
661
+ Default: [`dns.lookup`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback)
662
+
663
+ Custom DNS resolution logic.
664
+
665
+ The function signature is the same as [`dns.lookup`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).
666
+
658
667
  ###### request
659
668
 
660
669
  Type: `Function`\
@@ -873,12 +882,12 @@ got('https://api.github.com/some-endpoint', {
873
882
  beforeError: [
874
883
  error => {
875
884
  const {response} = error;
876
- if (response && response.body) {
885
+ if (response && response.body) {
877
886
  error.name = 'GitHubError';
878
887
  error.message = `${response.body.message} (${response.statusCode})`;
879
888
  }
880
889
 
881
- return error;
890
+ return error;
882
891
  }
883
892
  ]
884
893
  }
@@ -1696,43 +1705,44 @@ Additionaly, the errors may have `request` (Got Stream) and `response` (Got Resp
1696
1705
 
1697
1706
  #### got.RequestError
1698
1707
 
1699
- 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.
1700
1709
 
1701
1710
  #### got.CacheError
1702
1711
 
1703
- 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.
1704
1713
 
1705
1714
  #### got.ReadError
1706
1715
 
1707
- 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.
1708
1717
 
1709
1718
  #### got.ParseError
1710
1719
 
1711
- 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.
1712
1721
 
1713
1722
  #### got.UploadError
1714
1723
 
1715
- 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.
1716
1725
 
1717
1726
  #### got.HTTPError
1718
1727
 
1719
- 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
+
1720
1730
 
1721
1731
  #### got.MaxRedirectsError
1722
1732
 
1723
- 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`.
1724
1734
 
1725
1735
  #### got.UnsupportedProtocolError
1726
1736
 
1727
- When given an unsupported protocol.
1737
+ When given an unsupported protocol. Contains a `code` property with `ERR_UNSUPPORTED_PROTOCOL`.
1728
1738
 
1729
1739
  #### got.TimeoutError
1730
1740
 
1731
- 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`.
1732
1742
 
1733
1743
  #### got.CancelError
1734
1744
 
1735
- When the request is aborted with `.cancel()`.
1745
+ When the request is aborted with `.cancel()`. Contains a `code` property with `ERR_CANCELED`.
1736
1746
 
1737
1747
  ## Aborting the request
1738
1748