Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
07606cd996 | |||
3ca956e531 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.4.0",
|
||||
"version": "0.10.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.4.0",
|
||||
"version": "0.10.2",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.12",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.10.0",
|
||||
"version": "0.10.3",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
@ -1,15 +1,3 @@
|
||||
import {XHR} from './xhr';
|
||||
|
||||
XHR.addInterceptor((resp: Response, next: () => void) => {
|
||||
if(resp.status == 200) return next();
|
||||
if(resp.status == 400) throw new BadRequestError(resp.statusText);
|
||||
if(resp.status == 401) throw new UnauthorizedError(resp.statusText);
|
||||
if(resp.status == 403) throw new ForbiddenError(resp.statusText);
|
||||
if(resp.status == 404) throw new NotFoundError(resp.statusText);
|
||||
if(resp.status == 500) throw new InternalServerError(resp.statusText);
|
||||
throw new CustomError(resp.statusText, resp.status);
|
||||
});
|
||||
|
||||
export class CustomError extends Error {
|
||||
static code = 500;
|
||||
|
||||
|
@ -1,3 +1,11 @@
|
||||
import {
|
||||
BadRequestError,
|
||||
CustomError,
|
||||
ForbiddenError,
|
||||
InternalServerError,
|
||||
NotFoundError,
|
||||
UnauthorizedError
|
||||
} from './errors.ts';
|
||||
import {clean} from './objects';
|
||||
|
||||
export type Interceptor = (request: Response, next: () => void) => void;
|
||||
|
Reference in New Issue
Block a user