mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Setup exceptions structure
This commit is contained in:
12
src/exceptions/base.ts
Normal file
12
src/exceptions/base.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Code } from './types';
|
||||
|
||||
export class BaseException extends Error {
|
||||
status: number;
|
||||
code: Code;
|
||||
|
||||
constructor(message: string, status: number, code: Code) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
3
src/exceptions/index.ts
Normal file
3
src/exceptions/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './not-found';
|
||||
export * from './base';
|
||||
export * from './invalid-query';
|
||||
7
src/exceptions/invalid-query.ts
Normal file
7
src/exceptions/invalid-query.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { BaseException } from './base';
|
||||
|
||||
export class InvalidQueryException extends BaseException {
|
||||
constructor(message: string) {
|
||||
super(message, 400, 'INVALID_QUERY');
|
||||
}
|
||||
}
|
||||
19
src/exceptions/not-found.ts
Normal file
19
src/exceptions/not-found.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { BaseException } from './base';
|
||||
|
||||
export class RouteNotFound extends BaseException {
|
||||
constructor(path: string) {
|
||||
super(`Route ${path} doesn't exist.`, 404, 'ROUTE_NOT_FOUND');
|
||||
}
|
||||
}
|
||||
|
||||
export class CollectionNotFoundException extends BaseException {
|
||||
constructor(collection: string) {
|
||||
super(`Collection ${collection} can't be found.`, 404, 'COLLECTION_NOT_FOUND');
|
||||
}
|
||||
}
|
||||
|
||||
export class FieldNotFoundException extends BaseException {
|
||||
constructor(field: string) {
|
||||
super(`Field ${field} can't be found.`, 404, 'FIELD_NOT_FOUND');
|
||||
}
|
||||
}
|
||||
6
src/exceptions/types.ts
Normal file
6
src/exceptions/types.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export type Code =
|
||||
| 'COLLECTION_NOT_FOUND'
|
||||
| 'FIELD_NOT_FOUND'
|
||||
| 'ROUTE_NOT_FOUND'
|
||||
| 'NOT_FOUND'
|
||||
| 'INVALID_QUERY';
|
||||
Reference in New Issue
Block a user