export interface IGenericError extends Error {
  code: string;
  payload: Record<string, any>;
}

export class GenericError extends Error implements IGenericError {
  public readonly code: string;
  public readonly payload: Record<string, any> = {};

  protected constructor(code: string, message: string, payload = {}) {
    super(message);

    this.name = this.constructor.name;
    this.code = code;
    this.payload = payload;

    // 👇️ because we are extending a built-in class
    Object.setPrototypeOf(this, GenericError.prototype);
  }
}
