return the actual axios error with the custom error message in bruno-cli axios-instance

This commit is contained in:
lohit
2025-05-27 18:41:47 +05:30
parent 178773d63a
commit d820069371
2 changed files with 7 additions and 5 deletions

View File

@@ -92,14 +92,16 @@ function makeAxiosInstance({ requestMaxRedirects = 5, disableCookies } = {}) {
if (redirectResponseCodes.includes(error.response.status)) {
if (redirectCount >= requestMaxRedirects) {
const err = new Error(`Maximum redirects (${requestMaxRedirects}) exceeded`);
err.originalError = error;
return Promise.reject(err);
// todo: needs to be discussed whether the original error response message should be modified or not
error.response.data = `Maximum redirects (${requestMaxRedirects}) exceeded`;
return Promise.reject(error);
}
const locationHeader = error.response.headers.location;
if (!locationHeader) {
return Promise.reject(new Error('Redirect location header missing'));
// todo: needs to be discussed whether the original error response message should be modified or not
error.response.data = 'Redirect location header missing';
return Promise.reject(error);
}
redirectCount++;

View File

@@ -21,6 +21,6 @@ script:pre-request {
tests {
test("should disable redirect to ping", function() {
const data = res.getBody();
expect(data).to.equal('Found. Redirecting to /ping');
expect(data).to.not.equal('pong');
});
}