fix: fetch handler not passing back errors or success payloads

isekai-main
Julian Lam 2 years ago
parent ed99ea20cb
commit 8a53182657

@ -61,8 +61,17 @@ async function xhr(options, cb) {
await fetch(url, { await fetch(url, {
...options, ...options,
}).then((res) => { }).then(async (res) => {
cb(null, res); const payload = await res.json();
if (Math.floor(res.status / 100) === 2) {
cb(null, (
payload &&
payload.hasOwnProperty('status') &&
payload.hasOwnProperty('response') ? payload.response : (payload || {})
));
} else {
cb(new Error(payload.status.message));
}
}).catch(cb); }).catch(cb);
} else { } else {
options.data = JSON.stringify(options.payload || {}); options.data = JSON.stringify(options.payload || {});

Loading…
Cancel
Save