Commit cde33113 authored by Omar Luna Hernández's avatar Omar Luna Hernández
Browse files

Se crea el error de no autorizado

parent 37bcfa66
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
import { CustomError } from "./CustomError";

export default class UnauthorizedError extends CustomError {
  private static readonly _statusCode = 401;
  private readonly _code: number;
  private readonly _logging: boolean;
  private readonly _context: { [key: string]: any };

  constructor(params?: { code?: number; message?: string; logging?: boolean; context?: { [key: string]: any } }) {
    const { code, message, logging } = params || {};

    super(message || "You are not authorized");
    this._code = code || UnauthorizedError._statusCode;
    this._logging = logging || false;
    this._context = params?.context || {};

    Object.setPrototypeOf(this, UnauthorizedError.prototype);
  }

  get errors() {
    return [{ message: this.message, context: this._context }];
  }

  get statusCode() {
    return this._code;
  }

  get logging() {
    return this._logging;
  }
}