feat: Improve error handling in ContactPage and update Axios headers management

This commit is contained in:
Your Name
2026-03-18 00:07:18 +02:00
parent a2824b2132
commit ca20413667
2 changed files with 6 additions and 3 deletions

View File

@@ -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);

View File

@@ -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') {