|
|
@ -324,7 +324,7 @@ function asPromise(opts) { |
|
|
|
} |
|
|
|
|
|
|
|
if (statusCode !== 304 && (statusCode < 200 || statusCode > limitStatusCode)) { |
|
|
|
throw new got.HTTPError(statusCode, res.headers, opts); |
|
|
|
throw new got.HTTPError(statusCode, res.statusMessage, res.headers, opts); |
|
|
|
} |
|
|
|
|
|
|
|
resolve(res); |
|
|
@ -407,7 +407,7 @@ function asStream(opts) { |
|
|
|
res.pipe(output); |
|
|
|
|
|
|
|
if (statusCode !== 304 && (statusCode < 200 || statusCode > 299)) { |
|
|
|
proxy.emit('error', new got.HTTPError(statusCode, res.headers, opts), null, res); |
|
|
|
proxy.emit('error', new got.HTTPError(statusCode, res.statusMessage, res.headers, opts), null, res); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -627,8 +627,12 @@ got.ParseError = class extends StdError { |
|
|
|
}; |
|
|
|
|
|
|
|
got.HTTPError = class extends StdError { |
|
|
|
constructor(statusCode, headers, opts) { |
|
|
|
const statusMessage = http.STATUS_CODES[statusCode]; |
|
|
|
constructor(statusCode, statusMessage, headers, opts) { |
|
|
|
if (statusMessage) { |
|
|
|
statusMessage = statusMessage.replace(/\r?\n/g, ' ').trim(); |
|
|
|
} else { |
|
|
|
statusMessage = http.STATUS_CODES[statusCode]; |
|
|
|
} |
|
|
|
super(`Response code ${statusCode} (${statusMessage})`, {}, opts); |
|
|
|
this.name = 'HTTPError'; |
|
|
|
this.statusCode = statusCode; |
|
|
|