Files
turbostarter/packages/shared/src/utils/exceptions.ts
Alejandro Gutiérrez 3527e732d4 feat: turbostarter boilerplate
Production-ready Next.js boilerplate with:
- Runtime env validation (fail-fast on missing vars)
- Feature-gated config (S3, Stripe, email, OAuth)
- Docker + Coolify deployment pipeline
- PostgreSQL + pgvector, MinIO S3, Better Auth
- TypeScript strict mode (no ignoreBuildErrors)
- i18n (en/es), AI modules, billing, monitoring

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 01:01:55 +01:00

33 lines
861 B
TypeScript

import { HttpStatusCode } from "../constants";
export const isHttpStatus = (status: number): status is HttpStatusCode =>
Object.values<number>(HttpStatusCode).includes(status);
interface HttpExceptionOptions {
message?: string;
code?: string;
}
export class HttpException extends Error {
readonly status?: HttpStatusCode;
readonly code?: string;
constructor(status?: HttpStatusCode, options?: HttpExceptionOptions) {
super(options?.message);
this.status = status;
this.code = options?.code;
}
}
export const getStatusCode = (e: unknown) => {
if (typeof e === "object" && e && "status" in e) {
const status = Number(e.status);
// Guard against NaN or invalid status codes
if (!Number.isNaN(status) && status >= 200 && status <= 599) {
return status;
}
}
return HttpStatusCode.INTERNAL_SERVER_ERROR;
};