Files
MineGeo/lib/service-error.ts

17 lines
560 B
TypeScript

export class ServiceError extends Error {
constructor(
message: string,
public readonly status = 503,
) {
super(message);
}
}
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.");
}