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>
This commit is contained in:
32
packages/shared/src/utils/exceptions.ts
Normal file
32
packages/shared/src/utils/exceptions.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user