@@ -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 (
0 commit comments