Skip to content

Commit 763a383

Browse files
committed
fix: Improve error handling in report processing and update report status logic
1 parent f2bd6eb commit 763a383

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

backend/src/document-processor/controllers/document-processor.controller.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,9 @@ export class DocumentProcessorController {
187187
fileBuffer = await this.getFileFromS3(filePath);
188188
this.logger.log(`Successfully retrieved file from S3 for report: ${reportId}`);
189189
} catch (error) {
190-
this.logger.error(
191-
`Failed to retrieve file from S3 for report ${reportId}: ${error instanceof Error ? error.message : 'Unknown error'}`,
192-
);
193-
await this.updateReportStatus(reportId, userId, ProcessingStatus.FAILED);
190+
const errorMessage = `Failed to retrieve file from S3 for report ${reportId}: ${error instanceof Error ? error.message : 'Unknown error'}`;
191+
this.logger.error(errorMessage);
192+
await this.failReport(reportId, userId, errorMessage);
194193
return;
195194
}
196195

@@ -200,10 +199,9 @@ export class DocumentProcessorController {
200199
result = await this.documentProcessorService.processDocument(fileBuffer, userId);
201200
this.logger.log(`Successfully processed document for report: ${reportId}`);
202201
} catch (error) {
203-
this.logger.error(
204-
`Failed to process document for report ${reportId}: ${error instanceof Error ? error.message : 'Unknown error'}`,
205-
);
206-
await this.updateReportStatus(reportId, userId, ProcessingStatus.FAILED);
202+
const errorMessage = `Failed to process document for report ${reportId}: ${error instanceof Error ? error.message : 'Unknown error'}`;
203+
this.logger.error(errorMessage);
204+
await this.failReport(reportId, userId, errorMessage);
207205
return;
208206
}
209207

@@ -235,10 +233,9 @@ export class DocumentProcessorController {
235233
this.logger.log(`Completed async processing for report: ${reportId}`);
236234
} catch (error) {
237235
// If processing fails, update the report status to indicate failure
238-
this.logger.error(
239-
`Error during async processing for report ${reportId}: ${error instanceof Error ? error.message : 'Unknown error'}`,
240-
);
241-
await this.updateReportStatus(reportId, userId, ProcessingStatus.FAILED);
236+
const errorMessage = `Error during async processing for report ${reportId}: ${error instanceof Error ? error.message : 'Unknown error'}`;
237+
this.logger.error(errorMessage);
238+
await this.failReport(reportId, userId, errorMessage);
242239
}
243240
}
244241

@@ -248,20 +245,19 @@ export class DocumentProcessorController {
248245
* @param userId - ID of the user who owns the report
249246
* @param status - The new processing status
250247
*/
251-
private async updateReportStatus(
248+
private async failReport(
252249
reportId: string,
253250
userId: string,
254-
status: ProcessingStatus,
255251
debugMessage: string | undefined = undefined,
256252
): Promise<void> {
257253
try {
258254
const report = await this.reportsService.findOne(reportId, userId);
259255
if (report) {
260-
report.processingStatus = status;
256+
report.processingStatus = ProcessingStatus.FAILED;
261257
report.updatedAt = new Date().toISOString();
262258
report.debugMessage = debugMessage;
263259
await this.reportsService.updateReport(report);
264-
this.logger.log(`Updated status of report ${reportId} to ${status}`);
260+
this.logger.log(`Updated status of report ${reportId} to FAILED`);
265261
}
266262
} catch (updateError: unknown) {
267263
this.logger.error(

frontend/src/common/utils/i18n/resources/en/reportDetail.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@
9090
"original-report": "Original Report"
9191
}
9292
}
93-
}
93+
}

frontend/src/pages/Reports/ReportDetailPage.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
}
205205

206206
&__section-empty-icon {
207-
background-color: #EEF1FF;
207+
background-color: #eef1ff;
208208
border-radius: 50%;
209209
width: 90px;
210210
height: 90px;

0 commit comments

Comments
 (0)