This commit is contained in:
9
src/domain/errors/ApiError.ts
Normal file
9
src/domain/errors/ApiError.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Payload } from '../../types/Payload';
|
||||
import { ServiceError } from './ServiceError';
|
||||
|
||||
export class ApiError extends ServiceError {
|
||||
constructor(message: string, debug?: Payload) {
|
||||
super(message, debug);
|
||||
this.name = 'ApiError';
|
||||
}
|
||||
}
|
||||
9
src/domain/errors/DatabaseError.ts
Normal file
9
src/domain/errors/DatabaseError.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Payload } from '../../types/Payload';
|
||||
import { ServiceError } from './ServiceError';
|
||||
|
||||
export class DatabaseError extends ServiceError {
|
||||
constructor(message: string, debug?: Payload) {
|
||||
super(message, debug);
|
||||
this.name = 'DatabaseError';
|
||||
}
|
||||
}
|
||||
12
src/domain/errors/ServiceError.ts
Normal file
12
src/domain/errors/ServiceError.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Payload } from '../../types/Payload';
|
||||
|
||||
export class ServiceError extends Error {
|
||||
public env = process.env;
|
||||
public debug?: Payload;
|
||||
|
||||
constructor(message: string, debug?: Payload) {
|
||||
super(message);
|
||||
this.name = 'ServiceError';
|
||||
this.debug = debug;
|
||||
}
|
||||
}
|
||||
7
src/types/ApiResponse.ts
Normal file
7
src/types/ApiResponse.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Payload } from './Payload';
|
||||
|
||||
export interface ApiResponse<T = Payload> {
|
||||
data?: T;
|
||||
error?: Error | string | number;
|
||||
success: boolean;
|
||||
}
|
||||
7
src/types/Payload.ts
Normal file
7
src/types/Payload.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
type PayloadPrimitives = boolean | null | number | string;
|
||||
type PayloadArray = (PayloadPrimitives | Payload)[];
|
||||
type PayloadValid = PayloadPrimitives | PayloadArray | Payload;
|
||||
|
||||
export interface Payload<T = object> {
|
||||
[key: string]: PayloadValid | T;
|
||||
}
|
||||
Reference in New Issue
Block a user