M33: enforce booking readiness workflow

This commit is contained in:
NuklearRabbit
2026-08-10 22:23:11 +02:00
parent be33b46228
commit 82a933f6cd
12 changed files with 273 additions and 43 deletions
+27 -9
View File
@@ -12,15 +12,33 @@ export function onUnauthorized(listener: UnauthorizedListener): () => void {
return () => unauthorizedListeners.delete(listener);
}
const DEFAULT_TIMEOUT_MS = 15_000;
async function request<T>(path: string, init?: RequestInit): Promise<T> {
const response = await fetch(`${API_BASE}${path}`, {
...init,
credentials: "include",
headers: {
"Content-Type": "application/json",
...(init?.headers ?? {}),
},
});
const timeoutController = new AbortController();
const timeout = window.setTimeout(() => timeoutController.abort("timeout"), DEFAULT_TIMEOUT_MS);
const signal = init?.signal
? AbortSignal.any([init.signal, timeoutController.signal])
: timeoutController.signal;
let response: Response;
try {
response = await fetch(`${API_BASE}${path}`, {
...init,
signal,
credentials: "include",
headers: {
"Content-Type": "application/json",
...(init?.headers ?? {}),
},
});
} catch (error) {
if (timeoutController.signal.aborted && !init?.signal?.aborted) {
throw new ApiError(408, "REQUEST_TIMEOUT", "The request took too long.", "");
}
throw error;
} finally {
window.clearTimeout(timeout);
}
if (!response.ok) {
let body: { error?: { code: string; message: string; correlation_id: string } } | undefined;
@@ -48,7 +66,7 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
}
export const api = {
get: <T>(path: string) => request<T>(path),
get: <T>(path: string, init?: Pick<RequestInit, "signal">) => request<T>(path, init),
post: <T>(path: string, body?: unknown, headers?: Record<string, string>) =>
request<T>(path, { method: "POST", body: body ? JSON.stringify(body) : undefined, headers }),
patch: <T>(path: string, body: unknown) =>