Compare commits

..

No commits in common. "e72c7e105a41956b20738195321d124e90e76181" and "51ca53af88451819c117ca50d4825e81390ea08f" have entirely different histories.

View File

@ -452,7 +452,7 @@ export interface ContactFormResponse {
} }
/** /**
* Submit contact form (public endpoint - no authentication required) * Submit contact form
*/ */
export async function submitContactForm( export async function submitContactForm(
data: ContactFormInput data: ContactFormInput
@ -462,34 +462,18 @@ export async function submitContactForm(
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Accept": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
name: data.name.trim(), name: data.name,
email: data.email.trim().toLowerCase(), email: data.email,
phone: data.phone.trim(), phone: data.phone,
message: data.message.trim(), message: data.message,
}), }),
}); });
// Handle empty responses const responseData = await response.json();
const contentType = response.headers.get("content-type");
let responseData: any;
if (contentType && contentType.includes("application/json")) {
const text = await response.text();
responseData = text ? JSON.parse(text) : {};
} else {
const text = await response.text();
responseData = text ? { message: text } : {};
}
if (!response.ok) { if (!response.ok) {
// Check for authentication error specifically
if (response.status === 401 || response.status === 403) {
throw new Error("Contact form submission requires authentication. Please contact support if this is a public form.");
}
const error: ApiError = responseData; const error: ApiError = responseData;
throw new Error(extractErrorMessage(error)); throw new Error(extractErrorMessage(error));
} }
@ -499,7 +483,7 @@ export async function submitContactForm(
if (error instanceof Error) { if (error instanceof Error) {
throw error; throw error;
} }
throw new Error("Failed to submit contact form. Please try again later."); throw new Error("Failed to submit contact form");
} }
} }