Fix status code error message regression.
diff --git a/lib/client.js b/lib/client.js
index 47feba2..f304913 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -90,13 +90,16 @@
if (typeof error.error === 'string') {
return error.error
- } else if (error.response && error.response.result
- && error.response.result.error) {
- const err = error.response.result.error
- if (typeof err === 'string') {
- return err
- } else if (typeof err.error === 'string') {
- return err.error
+ } else if (error.response && error.response.result) {
+ const result = error.response.result
+ if (result.error) {
+ if (typeof result.error === 'string') {
+ return result.error
+ } else if (typeof result.error.error === 'string') {
+ return result.error.error
+ } else if (result.error.statusCode) {
+ return `application error, status code: ${result.error.statusCode}`
+ }
}
}
diff --git a/test/unit/client.test.js b/test/unit/client.test.js
index 285c6e5..5526ed6 100644
--- a/test/unit/client.test.js
+++ b/test/unit/client.test.js
@@ -111,6 +111,7 @@
t.throws(() => client.handle_errors({error: { error: 'hello' }, options: { method, url }, statusCode }), `${method} ${url} Returned HTTP ${statusCode} (${http.STATUS_CODES[statusCode]}) --> "hello"`)
t.throws(() => client.handle_errors({error: { response: { result: { error: 'hello' } } }, options: { method, url }, statusCode }), `${method} ${url} Returned HTTP ${statusCode} (${http.STATUS_CODES[statusCode]}) --> "hello"`)
t.throws(() => client.handle_errors({error: { response: { result: { error: { error: 'hello' } } } }, options: { method, url }, statusCode }), `${method} ${url} Returned HTTP ${statusCode} (${http.STATUS_CODES[statusCode]}) --> "hello"`)
+ t.throws(() => client.handle_errors({error: { response: { result: { error: { statusCode: 404 } } } }, options: { method, url }, statusCode }), `${method} ${url} Returned HTTP ${statusCode} (${http.STATUS_CODES[statusCode]}) --> "application error, status code: ${404}"`)
})
test('should throw errors for non-HTTP response failures', t => {