new error for HTTP responses without stack trace (#1044)

* new error for HTTP responses without stack trace

* lint
This commit is contained in:
Sam Machin
2025-01-16 13:05:17 +00:00
committed by GitHub
parent f71f0ac69a
commit 4dbc7df93d
2 changed files with 12 additions and 3 deletions

View File

@@ -17,8 +17,17 @@ class PlayFileNotFoundError extends NonFatalTaskError {
}
}
class HTTPResponseError extends Error {
constructor(statusCode) {
super('Unexpected HTTP Response');
delete this.stack;
this.statusCode = statusCode;
}
}
module.exports = {
SpeechCredentialError,
NonFatalTaskError,
PlayFileNotFoundError
PlayFileNotFoundError,
HTTPResponseError
};

View File

@@ -16,6 +16,7 @@ const {
NODE_ENV,
HTTP_USER_AGENT_HEADER,
} = require('../config');
const {HTTPResponseError} = require('./error');
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
@@ -190,8 +191,7 @@ class HttpRequestor extends BaseRequestor {
followRedirects: false
});
if (![200, 202, 204].includes(statusCode)) {
const err = new Error();
err.statusCode = statusCode;
const err = new HTTPResponseError(statusCode);
throw err;
}
if (headers['content-type']?.includes('application/json')) {