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 { PrismaService } from '../../infrastructure/database/prisma.service';
|
||||||
import { LearningSessionRepository } from '../learning-session/learning-session.repository';
|
import { LearningSessionRepository } from '../learning-session/learning-session.repository';
|
||||||
import { LearningActivityRepository } from '../learning-activity/learning-activity.repository';
|
import { LearningActivityRepository } from '../learning-activity/learning-activity.repository';
|
||||||
@ -36,6 +36,8 @@ interface ValidatedEvent {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ReadingEventProcessorService {
|
export class ReadingEventProcessorService {
|
||||||
|
private readonly logger = new Logger(ReadingEventProcessorService.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly sessionRepo: LearningSessionRepository,
|
private readonly sessionRepo: LearningSessionRepository,
|
||||||
@ -51,13 +53,19 @@ export class ReadingEventProcessorService {
|
|||||||
const result: ProcessResult = { processed: 0, duplicate: 0, failed: 0, warnings: [] };
|
const result: ProcessResult = { processed: 0, duplicate: 0, failed: 0, warnings: [] };
|
||||||
|
|
||||||
for (const e of events) {
|
for (const e of events) {
|
||||||
const { outcome, warnings } = await this.processOne(userId, e);
|
try {
|
||||||
switch (outcome) {
|
const { outcome, warnings } = await this.processOne(userId, e);
|
||||||
case 'processed': result.processed++; break;
|
switch (outcome) {
|
||||||
case 'duplicate': result.duplicate++; break;
|
case 'processed': result.processed++; break;
|
||||||
case 'failed': result.failed++; 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;
|
return result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user