Skip to content

Commit

Permalink
Attempting better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
richardp23 committed Jul 30, 2024
1 parent 9efc6f5 commit c27bdf0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/prep/PrepForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const PrepForm: React.FC<PrepFormProps> = ({ prepareInterview }) => {
e.preventDefault();
setIsLoading(true);
setError(null);
setResponse(null);

if (!file) {
setError('Please upload a resume');
Expand All @@ -34,10 +35,18 @@ const PrepForm: React.FC<PrepFormProps> = ({ 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);
}
Expand Down

0 comments on commit c27bdf0

Please sign in to comment.