Send event if request errors
This commit is contained in:
parent
2661e25cec
commit
5dca00d772
@ -40,15 +40,17 @@ export const fetchMixin = function(superClass) {
|
||||
|
||||
document.dispatchEvent(new CustomEvent('before-request', { detail: reqOptions, bubbles: true, composed: true }));
|
||||
|
||||
const result = await fetch(url, reqOptions).then(response => response.json());
|
||||
|
||||
const resp = await fetch(url, reqOptions);
|
||||
this.__abortControllers.delete(`${method}:${url}`);
|
||||
|
||||
if (result.statusCode === 500) {
|
||||
console.error(result);
|
||||
if (resp.status === 500) {
|
||||
console.error(resp);
|
||||
}
|
||||
|
||||
return result;
|
||||
if (resp.status !== 200) {
|
||||
document.dispatchEvent(new CustomEvent('request-error', { detail: resp, bubbles: true, composed: true }));
|
||||
}
|
||||
|
||||
return await resp.json();
|
||||
} catch (err) {
|
||||
if (err.name === 'AbortError') {
|
||||
return { statusCode: -1, error: err };
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tp/helpers",
|
||||
"version": "2.1.0",
|
||||
"version": "2.2.0",
|
||||
"description": "",
|
||||
"main": "closest.js",
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user