Skip to content

Commit

Permalink
Handle errors when not an array
Browse files Browse the repository at this point in the history
Fixes gh-71
Closes gh-73
  • Loading branch information
SaranshBS authored and scottgonzalez committed Dec 12, 2020
1 parent 40f9f9c commit 74676d4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ BaseClient.prototype.request = function(options, data, fn) {
if (res.headers["content-type"].indexOf("json") !== -1) {
response = JSON.parse(response);
message = response.message;
if (response.errors && response.errors.length) {
message += " - " + response.errors.map(function(error) {
return "`" + error.field + "` " + error.code;
}).join(", ");
if (response.errors) {
if (Array.isArray(response.errors) && response.errors.length) {
message += " - " + response.errors.map(function(error) {
return "`" + error.field + "` " + error.code;
}).join(", ");
} else {
message += " - " + response.errors.toString();
}
}
} else {
message = response;
Expand Down

0 comments on commit 74676d4

Please sign in to comment.