fix: add try-catch + error logging to processBatch
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 48s
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 48s
Prevents 500 from crashing the entire batch. Logs the actual error to server log for debugging. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
fb7ee358ce
commit
af8d95cdb6
@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
||||
import { LearningSessionRepository } from '../learning-session/learning-session.repository';
|
||||
import { LearningActivityRepository } from '../learning-activity/learning-activity.repository';
|
||||
@ -36,6 +36,8 @@ interface ValidatedEvent {
|
||||
|
||||
@Injectable()
|
||||
export class ReadingEventProcessorService {
|
||||
private readonly logger = new Logger(ReadingEventProcessorService.name);
|
||||
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly sessionRepo: LearningSessionRepository,
|
||||
@ -51,13 +53,19 @@ export class ReadingEventProcessorService {
|
||||
const result: ProcessResult = { processed: 0, duplicate: 0, failed: 0, warnings: [] };
|
||||
|
||||
for (const e of events) {
|
||||
const { outcome, warnings } = await this.processOne(userId, e);
|
||||
switch (outcome) {
|
||||
case 'processed': result.processed++; break;
|
||||
case 'duplicate': result.duplicate++; break;
|
||||
case 'failed': result.failed++; break;
|
||||
try {
|
||||
const { outcome, warnings } = await this.processOne(userId, e);
|
||||
switch (outcome) {
|
||||
case 'processed': result.processed++; break;
|
||||
case 'duplicate': result.duplicate++; break;
|
||||
case 'failed': result.failed++; break;
|
||||
}
|
||||
result.warnings.push(...warnings);
|
||||
} catch (err: any) {
|
||||
this.logger.error(`processOne failed for event ${e.eventId}: ${err.message}`, err.stack);
|
||||
result.failed++;
|
||||
result.warnings.push({ eventId: e.eventId, code: 'INTERNAL_ERROR', message: err.message });
|
||||
}
|
||||
result.warnings.push(...warnings);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user