mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
ignore invalid json on error pages
This commit is contained in:
parent
c8e4dbc1b3
commit
5ae1be9a9c
@ -85,7 +85,15 @@ export function createFetchRequest(createTimeout) {
|
||||
}
|
||||
const promise = fetch(url, options).then(async 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};
|
||||
}, err => {
|
||||
if (err.name === "AbortError") {
|
||||
|
@ -66,7 +66,7 @@ export function xhrRequest(url, options) {
|
||||
const xhr = send(url, options);
|
||||
const promise = xhrAsPromise(xhr, options.method, url).then(xhr => {
|
||||
const {status} = xhr;
|
||||
let body = xhr.responseText;
|
||||
let body = null;
|
||||
if (xhr.getResponseHeader("Content-Type") === "application/json") {
|
||||
body = JSON.parse(body);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user