Improve contact form error reporting
This commit is contained in:
parent
ddf38dda65
commit
0f4035b661
1 changed files with 9 additions and 1 deletions
|
|
@ -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.");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue