From 1195d1fadeeaa18767a9704504e0e66a3179299d Mon Sep 17 00:00:00 2001 From: Gianluigi Oliva Date: Sat, 7 Dec 2024 20:00:14 +0100 Subject: [PATCH] fix: response error interceptor --- lib/interceptor/response-error.js | 4 ++-- test/interceptors/response-error.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/interceptor/response-error.js b/lib/interceptor/response-error.js index 89ac1ee4ee0..70f0c3f67f2 100644 --- a/lib/interceptor/response-error.js +++ b/lib/interceptor/response-error.js @@ -81,8 +81,8 @@ class ResponseErrorHandler extends DecoratorHandler { } } - onResponseError (err) { - super.onResponseError(err) + onResponseError (controller, err) { + super.onResponseError(controller, err) } } diff --git a/test/interceptors/response-error.js b/test/interceptors/response-error.js index b0c0fb63498..996ff546098 100644 --- a/test/interceptors/response-error.js +++ b/test/interceptors/response-error.js @@ -168,3 +168,28 @@ test('should throw error for error response, parsing JSON without charset', asyn message: 'Bad Request' }) }) + +test('should throw error for networking errors response', async () => { + const client = new Client( + 'http://localhost:12345' + ).compose(responseError()) + + after(async () => { + await client.close() + }) + + let error + try { + await client.request({ + method: 'GET', + path: '/', + headers: { + 'content-type': 'text/plain' + } + }) + } catch (err) { + error = err + } + + assert.equal(error.code, 'ECONNREFUSED') +})