Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.8 kB ยท 71 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import type { ZodIssue } from "zod";
import type { ErrorCode } from "./error-code";
export function statusToCode(status: number): ErrorCode { switch (status) { case 400: return "BAD_REQUEST"; case 401: return "UNAUTHORIZED"; case 402: return "PAYMENT_REQUIRED"; case 403: return "FORBIDDEN"; case 404: return "NOT_FOUND"; case 405: return "METHOD_NOT_ALLOWED"; case 409: return "CONFLICT"; case 422: return "UNPROCESSABLE_ENTITY"; case 500: return "INTERNAL_SERVER_ERROR"; default: return "INTERNAL_SERVER_ERROR"; }}
export function codeToStatus(code: ErrorCode) { switch (code) { case "BAD_REQUEST": return 400; case "UNAUTHORIZED": return 401; case "PAYMENT_REQUIRED": return 402; case "FORBIDDEN": return 403; case "NOT_FOUND": return 404; case "METHOD_NOT_ALLOWED": return 405; case "CONFLICT": return 409; case "UNPROCESSABLE_ENTITY": return 422; case "INTERNAL_SERVER_ERROR": return 500; default: return 500; }}
// Props to cal.com: https://github.com/calcom/cal.com/blob/5d325495a9c30c5a9d89fc2adfa620b8fde9346e/packages/lib/server/getServerErrorFromUnknown.ts#L17export function parseZodErrorIssues(issues: ZodIssue[]): string { return issues .map((i) => i.code === "invalid_union" ? i.errors.map((ue) => parseZodErrorIssues(ue)).join("; ") : i.code === "unrecognized_keys" ? i.message : `${i.path.length ? `${i.code} in '${i.path}': ` : ""}${i.message}`, ) .join("; ");}
export function redactError<TError extends Error | unknown>(err: TError) { if (!(err instanceof Error)) return err; console.error(`Type of Error: ${err.constructor}`);}