Skip to content

Commit b405660

Browse files
authored
fix: show ims error response body message (#165)
1 parent af17f2c commit b405660

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/ims.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ async function _sendRequest (method, url, token, data) {
8787

8888
const retryOptions = { maxRetries: 3, initialDelayInMillis: 500 }
8989

90-
const validateResponse = (res) => {
90+
const validateResponse = async (res) => {
9191
if (res.status === 200) {
9292
return res
9393
}
94-
throw (new Error(`${res.status} (${res.statusText})`))
94+
throw (new Error(`${res.status} (${res.statusText}): ${await res.text()}`))
9595
}
9696

9797
const handleTextResponse = (text) => {

test/ims.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,8 @@ test('Ims.post throw error on unsuccessfully request', async () => {
696696
const ims = new Ims()
697697
const serverResponse = {
698698
status: 400,
699-
statusText: 'Bad Request'
699+
statusText: 'Bad Request',
700+
text: () => Promise.resolve('some error message')
700701
}
701702
mockExponentialBackoff.mockImplementationOnce(() => Promise.resolve(serverResponse))
702703
const result = ims.post('api', 'token', 'parameters')

0 commit comments

Comments
 (0)