import type { ExceptionResult } from "./exception-result";
import type { ExceptionCode } from "./exception-code";

export class AppException extends Error {
  readonly code: ExceptionCode;
  override readonly cause?: unknown;

  constructor(result: ExceptionResult, cause?: unknown) {
    super(result.message);
    this.name = "AppException";
    this.code = result.code;
    this.cause = cause;
  }

  toResult(): ExceptionResult {
    return {
      code: this.code,
      message: this.message,
    };
  }
}
