Improve contact form error reporting

This commit is contained in:
Calum Muir 2025-12-22 12:54:18 +00:00
parent ddf38dda65
commit 0f4035b661

View file

@ -64,8 +64,16 @@ export const Contact = (): JSX.Element => {
if (!response.ok) { if (!response.ok) {
const errorData = (await response.json().catch(() => null)) as { const errorData = (await response.json().catch(() => null)) as {
error?: string; error?: string;
details?: string;
} | null; } | null;
throw new Error(errorData?.error ?? "Request failed"); if (errorData?.error) {
throw new Error(errorData.error);
}
const errorText = await response.text().catch(() => "");
const message = errorText.trim()
? `${response.status} ${response.statusText}: ${errorText}`
: `${response.status} ${response.statusText}`;
throw new Error(message || "Request failed");
} }
setFormStatus("success"); setFormStatus("success");
setFormMessage("Thanks! Your message has been sent."); setFormMessage("Thanks! Your message has been sent.");