follow-redirects
Advanced tools
Comparing version 1.9.1 to 1.10.0
42
index.js
@@ -17,2 +17,20 @@ var url = require("url"); | ||
// Error types with codes | ||
var RedirectionError = createErrorType( | ||
"ERR_FR_REDIRECTION_FAILURE", | ||
"" | ||
); | ||
var TooManyRedirectsError = createErrorType( | ||
"ERR_FR_TOO_MANY_REDIRECTS", | ||
"Maximum number of redirects exceeded" | ||
); | ||
var MaxBodyLengthExceededError = createErrorType( | ||
"ERR_FR_MAX_BODY_LENGTH_EXCEEDED", | ||
"Request body larger than maxBodyLength limit" | ||
); | ||
var WriteAfterEndError = createErrorType( | ||
"ERR_STREAM_WRITE_AFTER_END", | ||
"write after end" | ||
); | ||
// An HTTP(S) request that can be redirected | ||
@@ -51,3 +69,3 @@ function RedirectableRequest(options, responseCallback) { | ||
if (this._ending) { | ||
throw new Error("write after end"); | ||
throw new WriteAfterEndError(); | ||
} | ||
@@ -57,3 +75,3 @@ | ||
if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) { | ||
throw new Error("data should be a string, Buffer or Uint8Array"); | ||
throw new TypeError("data should be a string, Buffer or Uint8Array"); | ||
} | ||
@@ -81,3 +99,3 @@ if (typeof encoding === "function") { | ||
else { | ||
this.emit("error", new Error("Request body larger than maxBodyLength limit")); | ||
this.emit("error", new MaxBodyLengthExceededError()); | ||
this.abort(); | ||
@@ -214,3 +232,3 @@ } | ||
if (!nativeProtocol) { | ||
this.emit("error", new Error("Unsupported protocol " + protocol)); | ||
this.emit("error", new TypeError("Unsupported protocol " + protocol)); | ||
return; | ||
@@ -304,3 +322,3 @@ } | ||
if (++this._redirectCount > this._options.maxRedirects) { | ||
this.emit("error", new Error("Max redirects exceeded.")); | ||
this.emit("error", new TooManyRedirectsError()); | ||
return; | ||
@@ -353,3 +371,3 @@ } | ||
catch (cause) { | ||
var error = new Error("Cannot redirect: " + cause.message); | ||
var error = new RedirectionError("Redirected request failed: " + cause.message); | ||
error.cause = cause; | ||
@@ -464,4 +482,16 @@ this.emit("error", error); | ||
function createErrorType(code, defaultMessage) { | ||
function CustomError(message) { | ||
Error.captureStackTrace(this, this.constructor); | ||
this.message = message || defaultMessage; | ||
} | ||
CustomError.prototype = new Error(); | ||
CustomError.prototype.constructor = CustomError; | ||
CustomError.prototype.name = "Error [" + code + "]"; | ||
CustomError.prototype.code = code; | ||
return CustomError; | ||
} | ||
// Exports | ||
module.exports = wrap({ http: http, https: https }); | ||
module.exports.wrap = wrap; |
{ | ||
"name": "follow-redirects", | ||
"version": "1.9.1", | ||
"version": "1.10.0", | ||
"description": "HTTP and HTTPS modules that follow redirects.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23170
441