mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-28 01:21:13 +01:00
fix: don't try to parse response if request is head #11960
This commit is contained in:
@@ -69,18 +69,23 @@ async function xhr(options, cb) {
|
|||||||
const isJSON = contentType && contentType.startsWith('application/json');
|
const isJSON = contentType && contentType.startsWith('application/json');
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
if (isJSON) {
|
if (options.method !== 'head') {
|
||||||
response = await res.json();
|
if (isJSON) {
|
||||||
} else {
|
response = await res.json();
|
||||||
response = await res.text();
|
} else {
|
||||||
|
response = await res.text();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
return cb(new Error(isJSON ? response.status.message : response));
|
if (response) {
|
||||||
|
return cb(new Error(isJSON ? response.status.message : response));
|
||||||
|
}
|
||||||
|
return cb(new Error(res.statusText));
|
||||||
}
|
}
|
||||||
|
|
||||||
cb(null, (
|
cb(null, (
|
||||||
isJSON && response.hasOwnProperty('status') && response.hasOwnProperty('response') ?
|
isJSON && response && response.hasOwnProperty('status') && response.hasOwnProperty('response') ?
|
||||||
response.response :
|
response.response :
|
||||||
response
|
response
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user