Skip to content

Commit ae6b98b

Browse files
committed
Refactor error handling in ProcessingPage to consolidate error state management using setError function. Ensure all user-facing text is internationalized.
1 parent f60546b commit ae6b98b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

frontend/src/pages/Processing/ProcessingPage.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ const ProcessingPage: React.FC = () => {
3939
}
4040
};
4141

42+
const setError = (heading: string | null, message: string | null) => {
43+
setErrorHeading(heading);
44+
setProcessingError(message);
45+
setIsProcessing(false);
46+
};
47+
4248
// Check the status of the report processing
4349
const checkReportStatus = async () => {
4450
if (!reportId) return;
@@ -69,17 +75,14 @@ const ProcessingPage: React.FC = () => {
6975
} else if (data.isMedicalReport === false) {
7076
setIsProcessing(false);
7177
clearStatusCheckInterval();
72-
setErrorHeading(missingDataHeading);
73-
setProcessingError(missingDataMessage);
78+
setError(missingDataHeading, missingDataMessage);
7479
} else if (data.status === 'failed') {
7580
throw new Error(failedMessage);
7681
}
7782
} catch (error) {
7883
setIsProcessing(false);
7984
clearStatusCheckInterval();
80-
81-
setErrorHeading(failedHeading);
82-
setProcessingError(error instanceof Error ? error.message : failedMessage);
85+
setError(failedHeading, error instanceof Error ? error.message : failedMessage);
8386
}
8487
};
8588

@@ -110,15 +113,15 @@ const ProcessingPage: React.FC = () => {
110113
statusCheckIntervalRef.current = window.setInterval(checkReportStatus, 2000);
111114
} catch (error) {
112115
console.error('Error processing file:', error);
113-
setProcessingError('Failed to process the file. Please try again.');
116+
setError('Processing Error', 'Failed to process the file. Please try again.');
114117
setIsProcessing(false);
115118
}
116119
};
117120

118121
// Handle retry attempt
119122
const execute = () => {
120123
// Reset error state and try processing the same file again
121-
setProcessingError(null);
124+
setError(null, null);
122125
setIsProcessing(true);
123126
lastTriggeredTime.current = Date.now();
124127
processFile();

0 commit comments

Comments
 (0)