Skip to content

Commit cc00864

Browse files
authored
Merge pull request #114 from ModusCreateOrg/ADE-66
[ADE-66] Enhance error handling in ReportsService for DynamoDB operations
2 parents 2e2a3d1 + 7c51c8c commit cc00864

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

backend/src/reports/reports.service.ts

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,18 @@ export class ReportsService {
287287
throw new InternalServerErrorException(
288288
`Table "${this.tableName}" not found. Please check your database configuration.`,
289289
);
290+
} else if (error.name === 'ValidationException') {
291+
this.logger.error(
292+
`DynamoDB validation error updating status for report ID ${id}: ${error.message}`,
293+
);
294+
throw new InternalServerErrorException(
295+
`Validation error updating report status: ${error.message}`,
296+
);
297+
} else if (error.name === 'ProvisionedThroughputExceededException') {
298+
this.logger.warn(`DynamoDB throughput exceeded for report ID ${id}`);
299+
throw new InternalServerErrorException(
300+
'Database capacity limit reached, please try again later',
301+
);
290302
}
291303
}
292304

@@ -390,10 +402,21 @@ export class ReportsService {
390402
id: report.id, // Sort key
391403
}),
392404
UpdateExpression:
393-
'SET title = :title, bookmarked = :bookmarked, category = :category, ' +
394-
'processingStatus = :processingStatus, labValues = :labValues, summary = :summary, ' +
395-
'confidence = :confidence, status = :status, updatedAt = :updatedAt',
405+
'SET #title = :title, #bookmarked = :bookmarked, #category = :category, ' +
406+
'#processingStatus = :processingStatus, #labValues = :labValues, #summary = :summary, ' +
407+
'#confidence = :confidence, #status = :status, #updatedAt = :updatedAt',
396408
ConditionExpression: 'userId = :userId', // Ensure the report belongs to the user
409+
ExpressionAttributeNames: {
410+
'#title': 'title',
411+
'#bookmarked': 'bookmarked',
412+
'#category': 'category',
413+
'#processingStatus': 'processingStatus',
414+
'#labValues': 'labValues',
415+
'#summary': 'summary',
416+
'#confidence': 'confidence',
417+
'#status': 'status',
418+
'#updatedAt': 'updatedAt',
419+
},
397420
ExpressionAttributeValues: marshall({
398421
':title': report.title,
399422
':bookmarked': report.bookmarked,
@@ -431,6 +454,18 @@ export class ReportsService {
431454
throw new InternalServerErrorException(
432455
`Table "${this.tableName}" not found. Please check your database configuration.`,
433456
);
457+
} else if (error.name === 'ValidationException') {
458+
this.logger.error(
459+
`DynamoDB validation error for report ID ${report.id}: ${error.message}`,
460+
);
461+
throw new InternalServerErrorException(
462+
`Validation error updating report: ${error.message}`,
463+
);
464+
} else if (error.name === 'ProvisionedThroughputExceededException') {
465+
this.logger.warn(`DynamoDB throughput exceeded for report ID ${report.id}`);
466+
throw new InternalServerErrorException(
467+
'Database capacity limit reached, please try again later',
468+
);
434469
}
435470
}
436471

@@ -505,6 +540,18 @@ export class ReportsService {
505540
throw new InternalServerErrorException(
506541
`Table "${this.tableName}" not found. Please check your database configuration.`,
507542
);
543+
} else if (error.name === 'ValidationException') {
544+
this.logger.error(
545+
`DynamoDB validation error toggling bookmark for report ID ${id}: ${error.message}`,
546+
);
547+
throw new InternalServerErrorException(
548+
`Validation error toggling bookmark: ${error.message}`,
549+
);
550+
} else if (error.name === 'ProvisionedThroughputExceededException') {
551+
this.logger.warn(`DynamoDB throughput exceeded for report ID ${id}`);
552+
throw new InternalServerErrorException(
553+
'Database capacity limit reached, please try again later',
554+
);
508555
}
509556
}
510557

0 commit comments

Comments
 (0)