Send event if request errors

This commit is contained in:
trading_peter 2023-10-05 12:28:51 +02:00
parent 2661e25cec
commit 5dca00d772
2 changed files with 9 additions and 7 deletions

View File

@ -40,15 +40,17 @@ export const fetchMixin = function(superClass) {
document.dispatchEvent(new CustomEvent('before-request', { detail: reqOptions, bubbles: true, composed: true })); 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}`); this.__abortControllers.delete(`${method}:${url}`);
if (resp.status === 500) {
if (result.statusCode === 500) { console.error(resp);
console.error(result);
} }
return result; if (resp.status !== 200) {
document.dispatchEvent(new CustomEvent('request-error', { detail: resp, bubbles: true, composed: true }));
}
return await resp.json();
} catch (err) { } catch (err) {
if (err.name === 'AbortError') { if (err.name === 'AbortError') {
return { statusCode: -1, error: err }; return { statusCode: -1, error: err };

View File

@ -1,6 +1,6 @@
{ {
"name": "@tp/helpers", "name": "@tp/helpers",
"version": "2.1.0", "version": "2.2.0",
"description": "", "description": "",
"main": "closest.js", "main": "closest.js",
"scripts": { "scripts": {