Files
MineGeo/lib/service-error.ts
pavel444-byte de0e891b62
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 3m40s
Add Void difficulty and publish changelogs
2026-10-20 14:05:01 +05:00

35 lines
993 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export class ServiceError extends Error {
constructor(
message: string,
public readonly status = 503,
) {
super(message);
}
}
export function checkDifficultyPresetError(
error: { message: string; code?: string } | null,
) {
if (error?.code === "23505")
throw new ServiceError("A difficulty with that name already exists", 409);
if (error?.code === "23514")
throw new ServiceError(
"Use a name with 2–40 characters and a round time of 5–600 seconds in 5-second steps",
400,
);
checkServiceError(error);
}
export function checkServiceError(
error: { message: string; code?: string } | null,
) {
if (!error) return;
if (error.code === "P0001") throw new Error(error.message);
if (error.code === "PGRST116")
throw new ServiceError("Record not found", 404);
console.error("Supabase request failed:", error.code, error.message);
throw new ServiceError(
"MineGeo could not reach its data service. Please try again.",
);
}