errors.ts 523 B

1234567891011121314151617181920
  1. /**
  2. * Structured API error handling.
  3. * Ported from PR #96 (Te9ui1a) — typed error codes for consistent JSON responses.
  4. */
  5. export class ApiError extends Error {
  6. readonly status: number;
  7. readonly code: string;
  8. constructor(status: number, code: string, message: string) {
  9. super(message);
  10. this.name = "ApiError";
  11. this.status = status;
  12. this.code = code;
  13. }
  14. }
  15. export function isMissingFileError(error: unknown): boolean {
  16. return (error as NodeJS.ErrnoException | undefined)?.code === "ENOENT";
  17. }