Browse Source

use `http.STATUS_CODES` ponyfill

Since the list differ between Node.js versions: https://github.com/nodejs/io.js/commit/8be6060020

This is different than the previous `statuses` module we used as this is a strict ponyfill for the built-in list.
http2
Sindre Sorhus 9 years ago
parent
commit
8045fc8741
  1. 5
      index.js
  2. 1
      package.json

5
index.js

@ -15,6 +15,7 @@ var isRedirect = require('is-redirect');
var PinkiePromise = require('pinkie-promise'); var PinkiePromise = require('pinkie-promise');
var unzipResponse = require('unzip-response'); var unzipResponse = require('unzip-response');
var createErrorClass = require('create-error-class'); var createErrorClass = require('create-error-class');
var nodeStatusCodes = require('node-status-codes');
function requestAsEventEmitter(opts) { function requestAsEventEmitter(opts) {
opts = opts || {}; opts = opts || {};
@ -278,14 +279,14 @@ got.ParseError = createErrorClass('ParseError', stdError);
got.HTTPError = createErrorClass('HTTPError', function (statusCode, opts) { got.HTTPError = createErrorClass('HTTPError', function (statusCode, opts) {
stdError.call(this, {}, opts); stdError.call(this, {}, opts);
this.statusCode = statusCode; this.statusCode = statusCode;
this.statusMessage = http.STATUS_CODES[this.statusCode]; this.statusMessage = nodeStatusCodes[this.statusCode];
this.message = 'Response code ' + this.statusCode + ' (' + this.statusMessage + ')'; this.message = 'Response code ' + this.statusCode + ' (' + this.statusMessage + ')';
}); });
got.MaxRedirectsError = createErrorClass('MaxRedirectsError', function (statusCode, opts) { got.MaxRedirectsError = createErrorClass('MaxRedirectsError', function (statusCode, opts) {
stdError.call(this, {}, opts); stdError.call(this, {}, opts);
this.statusCode = statusCode; this.statusCode = statusCode;
this.statusMessage = http.STATUS_CODES[this.statusCode]; this.statusMessage = nodeStatusCodes[this.statusCode];
this.message = 'Redirected 10 times. Aborting.'; this.message = 'Redirected 10 times. Aborting.';
}); });

1
package.json

@ -46,6 +46,7 @@
"is-redirect": "^1.0.0", "is-redirect": "^1.0.0",
"is-stream": "^1.0.0", "is-stream": "^1.0.0",
"lowercase-keys": "^1.0.0", "lowercase-keys": "^1.0.0",
"node-status-codes": "^1.0.0",
"object-assign": "^3.0.0", "object-assign": "^3.0.0",
"pinkie-promise": "^1.0.0", "pinkie-promise": "^1.0.0",
"prepend-http": "^1.0.0", "prepend-http": "^1.0.0",

Loading…
Cancel
Save