File size: 1,014 Bytes
d76f93d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { StatusCodes } from 'http-status-codes';

export class AppError extends Error {
    constructor(
      public message: string,
      public statusCode: number = StatusCodes.INTERNAL_SERVER_ERROR,
      public code?: string
    ) {
      super(message);
      this.name = this.constructor.name;
      Error.captureStackTrace(this, this.constructor);
    }
  }
  
  export class ValidationError extends AppError {
    constructor(message: string) {
      super(message, StatusCodes.BAD_REQUEST, "VALIDATION_ERROR");
    }
  }
  
  export class NotFoundError extends AppError {
    constructor(message: string) {
      super(message, StatusCodes.NOT_FOUND, "NOT_FOUND");
    }
  }
  
  export class DatabaseError extends AppError {
    constructor(message: string) {
      super(message, StatusCodes.INTERNAL_SERVER_ERROR, "DATABASE_ERROR");
    }
  }

  export class BadRequestError extends AppError {
    constructor(message: string) {
      super(message, StatusCodes.BAD_REQUEST, "BAD_REQUEST");
    }
  }