Skip to content

Commit 3c67a3d

Browse files
authored
Make the responseError interceptor backward compatible, add a body property (#3891)
Signed-off-by: Matteo Collina <[email protected]>
1 parent de6aea6 commit 3c67a3d

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/core/errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ class RequestRetryError extends UndiciError {
196196
}
197197

198198
class ResponseError extends UndiciError {
199-
constructor (message, code, { headers, data }) {
199+
constructor (message, code, { headers, body }) {
200200
super(message)
201201
this.name = 'ResponseError'
202202
this.message = message || 'Response error'
203203
this.code = 'UND_ERR_RESPONSE'
204204
this.statusCode = code
205-
this.data = data
205+
this.body = body
206206
this.headers = headers
207207
}
208208
}

lib/interceptor/response-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ResponseErrorHandler extends DecoratorHandler {
6666
Error.stackTraceLimit = 0
6767
try {
6868
err = new ResponseError('Response Error', this.#statusCode, {
69-
data: this.#body,
69+
body: this.#body,
7070
headers: this.#headers
7171
})
7272
} finally {

test/interceptors/response-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test('should throw error for error response', async () => {
4545

4646
assert.equal(error.statusCode, 400)
4747
assert.equal(error.message, 'Response Error')
48-
assert.equal(error.data, 'Bad Request')
48+
assert.equal(error.body, 'Bad Request')
4949
})
5050

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

0 commit comments

Comments
 (0)