Removed custom errors from xhr helper
This commit is contained in:
parent
3ca956e531
commit
07606cd996
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.4.0",
|
"version": "0.10.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.4.0",
|
"version": "0.10.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.12",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.10.1",
|
"version": "0.10.3",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
11
src/xhr.ts
11
src/xhr.ts
@ -82,14 +82,3 @@ export class XHR {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XHR.addInterceptor((resp: Response, next: () => void) => {
|
|
||||||
const getErr = (e: any) => e.error?.message || e.reason?.message || e.message || e.statusText || e.toString();
|
|
||||||
if(resp.status == 200) return next();
|
|
||||||
if(resp.status == 400) throw new BadRequestError(getErr(resp));
|
|
||||||
if(resp.status == 401) throw new UnauthorizedError(getErr(resp));
|
|
||||||
if(resp.status == 403) throw new ForbiddenError(getErr(resp));
|
|
||||||
if(resp.status == 404) throw new NotFoundError(getErr(resp));
|
|
||||||
if(resp.status == 500) throw new InternalServerError(getErr(resp));
|
|
||||||
throw new CustomError(getErr(resp), resp.status);
|
|
||||||
});
|
|
||||||
|
Loading…
Reference in New Issue
Block a user