Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 895aec2

Browse files
richardschneiderdaviddias
authored andcommitted
fix: not all error messages are in JSON
1 parent e8301c8 commit 895aec2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/utils/request-api.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ function onRes (buffer, cb) {
5757
res.on('end', () => {
5858
let err = res.trailers['x-stream-error']
5959
if (err) {
60-
err = JSON.parse(err)
60+
// Not all errors are JSON
61+
try {
62+
err = JSON.parse(err)
63+
} catch (e) {
64+
err = {
65+
Code: 'n/a',
66+
Message: err
67+
}
68+
}
6169
const error = new Error(`Server responded with 500`)
6270
error.code = err.Code
6371
error.message = err.Message

0 commit comments

Comments
 (0)