Validate and deduplicate custom difficulty presets
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 6m4s
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 6m4s
This commit is contained in:
@@ -7,10 +7,28 @@ export class ServiceError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export function checkServiceError(error: { message: string; code?: string } | null) {
|
||||
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 15–600 seconds in 15-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);
|
||||
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.");
|
||||
throw new ServiceError(
|
||||
"MineGeo could not reach its data service. Please try again.",
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user