diff --git a/src/components/casoEspecial/caso-especial-form.tsx b/src/components/casoEspecial/caso-especial-form.tsx index c4e4f47..b3ef238 100644 --- a/src/components/casoEspecial/caso-especial-form.tsx +++ b/src/components/casoEspecial/caso-especial-form.tsx @@ -8,7 +8,7 @@ import { Col, FormGroup, FormLabel, InputGroup } from 'react-bootstrap'; import { FaRegCalendarAlt, FaUpload } from 'react-icons/fa'; import DatePicker from 'react-datepicker'; import BotonRegresar from '../boton-regresar'; -import axios from 'axios'; +import axios from "axios"; import Image from 'next/image'; // 🔹 Tipos estrictos @@ -193,19 +193,42 @@ export default function CasoEspecialForm({ setNumeroCuenta(''); imprimirMensaje(res.data.message); } catch (err: unknown) { - let msg: { message: string } = { message: 'Error al enviar formulario.' }; - if (typeof err === 'object' && err !== null && 'response' in err) { - const anyErr = err as { response?: { data?: unknown } }; - if (anyErr.response && typeof anyErr.response.data === 'object' && anyErr.response.data !== null) { - const d = anyErr.response.data as { message?: unknown } | unknown; - if (d && typeof d === 'object' && 'message' in d && typeof (d as { message?: unknown }).message === 'string') { - msg = { message: (d as { message?: unknown }).message as string }; - } - } - } else if (err instanceof Error) { - msg = { message: err.message }; - } - imprimirError(msg); + // Quitar esta parte + if (axios.isAxiosError(err)) { + + const backendMessage = err.response?.data?.message; + + if (backendMessage) { + + // Si el backend manda string + if (typeof backendMessage === "string") { + imprimirError({ message: backendMessage }); + return; + } + + // Si el backend manda arreglo (NestJS validation) + if (Array.isArray(backendMessage)) { + imprimirError({ message: backendMessage.join("\n") }); + return; + } + } + } + + // Fallback SOLO si no vino nada del backend + imprimirError({ message: "Error inesperado del servidor" }); + // let msg: { message: string } = { message: 'Error al enviar formulario.' }; + // if (typeof err === 'object' && err !== null && 'response' in err) { + // const anyErr = err as { response?: { data?: unknown } }; + // if (anyErr.response && typeof anyErr.response.data === 'object' && anyErr.response.data !== null) { + // const d = anyErr.response.data as { message?: unknown } | unknown; + // if (d && typeof d === 'object' && 'message' in d && typeof (d as { message?: unknown }).message === 'string') { + // msg = { message: (d as { message?: unknown }).message as string }; + // } + // } + // } else if (err instanceof Error) { + // msg = { message: err.message }; + // } + // imprimirError(msg); } finally { updateIsLoading(false); } @@ -314,7 +337,7 @@ export default function CasoEspecialForm({