mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-26 16:41:21 +01:00
fix: fetch handler not passing back errors or success payloads
This commit is contained in:
@@ -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 || {});
|
||||||
|
|||||||
Reference in New Issue
Block a user