Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the responseError interceptor backward compatible, add a body property #3891

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/core/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ class RequestRetryError extends UndiciError {
}

class ResponseError extends UndiciError {
constructor (message, code, { headers, data }) {
constructor (message, code, { headers, body }) {
super(message)
this.name = 'ResponseError'
this.message = message || 'Response error'
this.code = 'UND_ERR_RESPONSE'
this.statusCode = code
this.data = data
this.body = body
this.headers = headers
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/interceptor/response-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ResponseErrorHandler extends DecoratorHandler {
Error.stackTraceLimit = 0
try {
err = new ResponseError('Response Error', this.#statusCode, {
data: this.#body,
body: this.#body,
headers: this.#headers
})
} finally {
Expand Down
2 changes: 1 addition & 1 deletion test/interceptors/response-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test('should throw error for error response', async () => {

assert.equal(error.statusCode, 400)
assert.equal(error.message, 'Response Error')
assert.equal(error.data, 'Bad Request')
assert.equal(error.body, 'Bad Request')
})

test('should not throw error for ok response', async () => {
Expand Down
Loading