Initial implementation
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
export class GatewayError extends Error {
|
||||
public constructor(
|
||||
public readonly statusCode: number,
|
||||
public readonly code: string,
|
||||
message: string,
|
||||
public readonly details: Record<string, unknown> = {},
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'GatewayError';
|
||||
}
|
||||
}
|
||||
|
||||
export const badRequest = (code: string, message: string, details: Record<string, unknown> = {}) =>
|
||||
new GatewayError(400, code, message, details);
|
||||
|
||||
export const forbidden = (code: string, message: string) => new GatewayError(403, code, message);
|
||||
export const notFound = (code: string, message: string) => new GatewayError(404, code, message);
|
||||
export const conflict = (code: string, message: string) => new GatewayError(409, code, message);
|
||||
export const unprocessable = (code: string, message: string) => new GatewayError(422, code, message);
|
||||
|
||||
export function asError(value: unknown): Error {
|
||||
return value instanceof Error ? value : new Error(String(value));
|
||||
}
|
||||
Reference in New Issue
Block a user