Skip to content

Commit

Permalink
feat(FEC-8316): protect against invalid server response (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrenMe authored Jun 17, 2018
1 parent 8d55207 commit de5d5e3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/util/request-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ export default class RequestBuilder {
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status === 200) {
let jsonResponse = JSON.parse(request.responseText);
let jsonResponse;
try {
jsonResponse = JSON.parse(request.responseText);
} catch (e) {
return reject(`${e.message}, ${request.responseText}`);
}
if (jsonResponse && typeof(jsonResponse) === 'object' && jsonResponse.code && jsonResponse.message)
reject(jsonResponse);
else
Expand Down

0 comments on commit de5d5e3

Please sign in to comment.