Check HTTP status before parsing body in fetchJson (#280).
This commit is contained in:
parent
b9829f205f
commit
892f30a051
@ -113,6 +113,15 @@ export function fetchJson(connection: string | ConnectionInfo, json: string, pro
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState !== 4) { return; }
|
||||
|
||||
if (request.status != 200) {
|
||||
cancelTimeout();
|
||||
// @TODO: not any!
|
||||
let error: any = new Error('invalid response - ' + request.status);
|
||||
error.statusCode = request.status;
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
let result: any = null;
|
||||
try {
|
||||
result = JSON.parse(request.responseText);
|
||||
@ -140,15 +149,6 @@ export function fetchJson(connection: string | ConnectionInfo, json: string, pro
|
||||
}
|
||||
}
|
||||
|
||||
if (request.status != 200) {
|
||||
cancelTimeout();
|
||||
// @TODO: not any!
|
||||
let error: any = new Error('invalid response - ' + request.status);
|
||||
error.statusCode = request.status;
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
cancelTimeout();
|
||||
resolve(result);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user