Gracefully handle missing DB in Planner routes
Wrap session API and loader in try/catch to return 503 instead of crashing the server when PostgreSQL is unavailable. This prevents E2E test failures in CI where no DB is running. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e86ff5a8a3
commit
cadcf753a7
2 changed files with 43 additions and 27 deletions
|
|
@ -15,29 +15,40 @@ export async function action({ request }: Route.ActionArgs) {
|
||||||
gpx?: string;
|
gpx?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const session = await createSession({ callbackUrl, callbackToken });
|
try {
|
||||||
|
const session = await createSession({ callbackUrl, callbackToken });
|
||||||
|
|
||||||
let initialWaypoints: Array<{ lat: number; lon: number; name?: string }> | undefined;
|
let initialWaypoints: Array<{ lat: number; lon: number; name?: string }> | undefined;
|
||||||
if (gpx) {
|
if (gpx) {
|
||||||
try {
|
try {
|
||||||
const gpxData = await parseGpxAsync(gpx);
|
const gpxData = await parseGpxAsync(gpx);
|
||||||
initialWaypoints = gpxData.waypoints;
|
initialWaypoints = gpxData.waypoints;
|
||||||
} catch (_e) {
|
} catch {
|
||||||
// Continue with empty session if GPX is invalid
|
// Continue with empty session if GPX is invalid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return data(
|
return data(
|
||||||
{
|
{
|
||||||
sessionId: session.id,
|
sessionId: session.id,
|
||||||
url: `/session/${session.id}`,
|
url: `/session/${session.id}`,
|
||||||
initialWaypoints,
|
initialWaypoints,
|
||||||
},
|
},
|
||||||
{ status: 201 },
|
{ status: 201 },
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
return data(
|
||||||
|
{ error: "Database unavailable", details: (e as Error).message },
|
||||||
|
{ status: 503 },
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loader(_args: Route.LoaderArgs) {
|
export async function loader(_args: Route.LoaderArgs) {
|
||||||
const sessions = await listSessions();
|
try {
|
||||||
return data({ sessions });
|
const sessions = await listSessions();
|
||||||
|
return data({ sessions });
|
||||||
|
} catch {
|
||||||
|
return data({ sessions: [], error: "Database unavailable" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,20 @@ export function meta(_args: Route.MetaArgs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loader({ params }: Route.LoaderArgs) {
|
export async function loader({ params }: Route.LoaderArgs) {
|
||||||
const session = await getSession(params.id);
|
try {
|
||||||
if (!session) {
|
const session = await getSession(params.id);
|
||||||
throw data({ error: "Session not found" }, { status: 404 });
|
if (!session) {
|
||||||
|
throw data({ error: "Session not found" }, { status: 404 });
|
||||||
|
}
|
||||||
|
return data({
|
||||||
|
sessionId: session.id,
|
||||||
|
callbackUrl: session.callbackUrl ?? null,
|
||||||
|
callbackToken: session.callbackToken ?? null,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof Response) throw e; // Re-throw data() responses
|
||||||
|
throw data({ error: "Database unavailable" }, { status: 503 });
|
||||||
}
|
}
|
||||||
return data({
|
|
||||||
sessionId: session.id,
|
|
||||||
callbackUrl: session.callbackUrl ?? null,
|
|
||||||
callbackToken: session.callbackToken ?? null,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SessionPage({ loaderData }: Route.ComponentProps) {
|
export default function SessionPage({ loaderData }: Route.ComponentProps) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue