export class CustomError extends Error {
  statusCode: number;
  code: string;

  constructor(statusCode: number, code: string, message?: string) {
    super(message || code);
    this.statusCode = statusCode;
    this.code = code;
  }
}

export function formatError(err: any) {
  return { code: err.code || 'UNKNOWN', message: err.message };
}

export function getStatusFromError(err: any) {
  return err.statusCode || 500;
}
