fix: don't try to parse response if request is head #11960

isekai-main
Barış Soner Uşaklı 1 year ago
parent 50d44777fa
commit 440299e661

@ -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 (options.method !== 'head') {
if (isJSON) { if (isJSON) {
response = await res.json(); response = await res.json();
} else { } else {
response = await res.text(); response = await res.text();
} }
}
if (!res.ok) { if (!res.ok) {
if (response) {
return cb(new Error(isJSON ? response.status.message : 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
)); ));

Loading…
Cancel
Save