From ca20413667112f38a858f8829c54426ddc4ea5b3 Mon Sep 17 00:00:00 2001 From: Your Name <119736744+aborayan2022@users.noreply.github.com> Date: Wed, 18 Mar 2026 00:07:18 +0200 Subject: [PATCH] feat: Improve error handling in ContactPage and update Axios headers management --- frontend/src/pages/ContactPage.tsx | 7 +++++-- frontend/src/services/api.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/ContactPage.tsx b/frontend/src/pages/ContactPage.tsx index de8fbb7..e48b0bd 100644 --- a/frontend/src/pages/ContactPage.tsx +++ b/frontend/src/pages/ContactPage.tsx @@ -2,6 +2,7 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Helmet } from 'react-helmet-async'; import { Mail, Send, CheckCircle, AlertCircle, Loader2 } from 'lucide-react'; +import { isAxiosError } from 'axios'; import SEOHead from '@/components/seo/SEOHead'; import { generateWebPage, getSiteOrigin } from '@/utils/seo'; import { getApiClient } from '@/services/api'; @@ -40,10 +41,12 @@ export default function ContactPage() { }); setSubmitted(true); } catch (err: unknown) { - if (err instanceof Error) { + if (isAxiosError(err) && err.response?.data?.error) { + setError(err.response.data.error); + } else if (err instanceof Error) { setError(err.message); } else { - setError(err.response.data.error); + setError(String(err)); } } finally { setLoading(false); diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index 97ba407..efeac17 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -35,7 +35,7 @@ function shouldAttachCsrfToken(config: InternalAxiosRequestConfig): boolean { function setRequestHeader(config: InternalAxiosRequestConfig, key: string, value: string) { if (!config.headers) { - config.headers = {}; + config.headers = new axios.AxiosHeaders(); } if (typeof (config.headers as { set?: (header: string, headerValue: string) => void }).set === 'function') {