Add visible feedback and error handling to commission requests

This commit is contained in:
2026-01-01 11:53:13 +01:00
parent 84470aa2e2
commit af5e2dd590
3 changed files with 223 additions and 161 deletions

View File

@ -67,22 +67,32 @@ export async function submitCommissionRequest(input: {
);
if (!res.ok) {
const text = await res.text().catch(() => "");
let parsed: any = null;
const raw = await res.text().catch(() => "");
const statusLine = `${res.status} ${res.statusText || ""}`.trim();
// Show something useful even if raw is empty
let message = `Admin API error: ${statusLine}`;
if (raw) {
try {
parsed = text ? JSON.parse(text) : null;
const parsed = JSON.parse(raw);
message =
parsed?.error
? `Admin API error: ${statusLine}${parsed.error}`
: parsed?.message
? `Admin API error: ${statusLine}${parsed.message}`
: `Admin API error: ${statusLine}${raw}`;
} catch {
// ignore
message = `Admin API error: ${statusLine}${raw}`;
}
const message =
parsed?.error ??
parsed?.message ??
(text ? text.slice(0, 300) : `Request failed (${res.status})`);
throw new Error(message);
}
// Log full body server-side for debugging (safe; this is server-only)
console.error("[submitCommissionRequest] upstream error", { statusLine, raw });
throw new Error(message);
}
// Expected response: { id: string; createdAt: string }
return (await res.json()) as { id: string; createdAt: string };
}