ignore invalid json on error pages
This commit is contained in:
parent
c8e4dbc1b3
commit
5ae1be9a9c
2 changed files with 10 additions and 2 deletions
|
@ -85,7 +85,15 @@ export function createFetchRequest(createTimeout) {
|
||||||
}
|
}
|
||||||
const promise = fetch(url, options).then(async response => {
|
const promise = fetch(url, options).then(async response => {
|
||||||
const {status} = response;
|
const {status} = response;
|
||||||
const body = await response.json();
|
let body;
|
||||||
|
try {
|
||||||
|
body = await response.json();
|
||||||
|
} catch (err) {
|
||||||
|
// some error pages return html instead of json, ignore error
|
||||||
|
if (!(err.name === "SyntaxError" && status >= 400)) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
return {status, body};
|
return {status, body};
|
||||||
}, err => {
|
}, err => {
|
||||||
if (err.name === "AbortError") {
|
if (err.name === "AbortError") {
|
||||||
|
|
|
@ -66,7 +66,7 @@ export function xhrRequest(url, options) {
|
||||||
const xhr = send(url, options);
|
const xhr = send(url, options);
|
||||||
const promise = xhrAsPromise(xhr, options.method, url).then(xhr => {
|
const promise = xhrAsPromise(xhr, options.method, url).then(xhr => {
|
||||||
const {status} = xhr;
|
const {status} = xhr;
|
||||||
let body = xhr.responseText;
|
let body = null;
|
||||||
if (xhr.getResponseHeader("Content-Type") === "application/json") {
|
if (xhr.getResponseHeader("Content-Type") === "application/json") {
|
||||||
body = JSON.parse(body);
|
body = JSON.parse(body);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue