From 3c67a3d7474a33964621c934215ce7da3e31ede2 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 27 Nov 2024 14:37:52 +0100 Subject: [PATCH] Make the responseError interceptor backward compatible, add a body property (#3891) Signed-off-by: Matteo Collina --- lib/core/errors.js | 4 ++-- lib/interceptor/response-error.js | 2 +- test/interceptors/response-error.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core/errors.js b/lib/core/errors.js index 7a68cf813a5..b2b3f326bc4 100644 --- a/lib/core/errors.js +++ b/lib/core/errors.js @@ -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 } } diff --git a/lib/interceptor/response-error.js b/lib/interceptor/response-error.js index 5ecf52f446f..07f9ec788b7 100644 --- a/lib/interceptor/response-error.js +++ b/lib/interceptor/response-error.js @@ -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 { diff --git a/test/interceptors/response-error.js b/test/interceptors/response-error.js index 5f9f0bb5bb1..fb0a1c91391 100644 --- a/test/interceptors/response-error.js +++ b/test/interceptors/response-error.js @@ -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 () => {