From c27bdf0943eca9117112c9d9148760a55aa37f57 Mon Sep 17 00:00:00 2001 From: "Richard Perez Jr." Date: Tue, 30 Jul 2024 01:20:56 -0400 Subject: [PATCH] Attempting better error handling --- src/components/prep/PrepForm.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/prep/PrepForm.tsx b/src/components/prep/PrepForm.tsx index 3ae18ee..4d36f87 100644 --- a/src/components/prep/PrepForm.tsx +++ b/src/components/prep/PrepForm.tsx @@ -21,6 +21,7 @@ const PrepForm: React.FC = ({ prepareInterview }) => { e.preventDefault(); setIsLoading(true); setError(null); + setResponse(null); if (!file) { setError('Please upload a resume'); @@ -34,10 +35,18 @@ const PrepForm: React.FC = ({ prepareInterview }) => { try { const result = await prepareInterview(formData); - setResponse(result.response); + if (result && result.response) { + setResponse(result.response); + } else { + throw new Error('Invalid response from server'); + } } catch (err) { - setError('An error occurred while preparing your interview'); - console.error(err); + console.error('Error in prepareInterview:', err); + if (err instanceof Error) { + setError(`An error occurred: ${err.message}`); + } else { + setError('An unexpected error occurred while preparing your interview'); + } } finally { setIsLoading(false); }