Skip to content

Commit

Permalink
fix: response error interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigioliva committed Dec 7, 2024
1 parent cac18e1 commit 1195d1f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/interceptor/response-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class ResponseErrorHandler extends DecoratorHandler {
}
}

onResponseError (err) {
super.onResponseError(err)
onResponseError (controller, err) {
super.onResponseError(controller, err)
}
}

Expand Down
25 changes: 25 additions & 0 deletions test/interceptors/response-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

0 comments on commit 1195d1f

Please sign in to comment.