diff --git a/lib/redirect.js b/lib/redirect.js index a27026869..3c98495fa 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -123,7 +123,11 @@ Redirect.prototype.onResponse = function (response, callback) { } var uriPrev = request.uri - request.uri = urlParser.parse(redirectTo) + try { + request.uri = urlParser.parse(redirectTo) + } catch (e) { + return callback(new Error('Failed to parse url: ' + request.uri.href)) + } // handle the case where we change protocol from https to http or vice versa if (request.uri.protocol !== uriPrev.protocol && self.allowInsecureRedirect) {