export class AppError extends Error {
  constructor(
    public code: string,
    message: string,
    public statusCode: number = 400,
  ) {
    super(message)
    this.name = 'AppError'
  }
}

export function isAppError(err: unknown): err is AppError {
  return err instanceof AppError
}

export function throwAppError(code: string, message: string, statusCode: number = 400): never {
  throw new AppError(code, message, statusCode)
}
