From 7fcd58602417b520bd8695a707d658e5586857c3 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 8 Jul 2025 10:26:33 -0400 Subject: [PATCH] Include status message (reason phrase) in error message When an HTTP request fails, the status code and description is logged/output. That description currently is derived by mapping the status code to a predefined mapping of messages. This change uses the HTTP response status line reason phrase if it is available, falling back to the predefined mapping to a message if the server didn't provide one. The reason phrase that the server responds with may have more information that will be helpful for the user. For example, Sonatype Nexus Firewall includes a message in the reason phrase indicating the requested package is blocked. Other software similarly returns useful information in the reason phrase. See: * https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html * https://nodejs.org/api/http.html#messagestatusmessage --- src/util/request-manager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/request-manager.js b/src/util/request-manager.js index fd41bf2100..17bae6357c 100644 --- a/src/util/request-manager.js +++ b/src/util/request-manager.js @@ -425,7 +425,7 @@ export default class RequestManager { this.reporter.verbose(this.reporter.lang('verboseRequestFinish', params.url, res.statusCode)); if (res.statusCode === 408 || res.statusCode >= 500) { - const description = `${res.statusCode} ${http.STATUS_CODES[res.statusCode]}`; + const description = `${res.statusCode} ${res.statusMessage || http.STATUS_CODES[res.statusCode]}`; if (!queueForRetry(this.reporter.lang('internalServerErrorRetrying', description))) { throw new ResponseError(this.reporter.lang('requestFailed', description), res.statusCode); } else { @@ -517,7 +517,7 @@ export default class RequestManager { return; } - const description = `${res.statusCode} ${http.STATUS_CODES[res.statusCode]}`; + const description = `${res.statusCode} ${res.statusMessage || http.STATUS_CODES[res.statusCode]}`; reject(new ResponseError(this.reporter.lang('requestFailed', description), res.statusCode)); req.abort();