apps/recallassess/recallassess-api/src/common/adapters/recallassess-global-exception-log-writer.service.ts
Methods |
|
constructor(prisma: BNestPrismaService, http500Notification: SystemLogHttp500NotificationService)
|
|||||||||
|
Parameters :
|
| Async write | ||||||
write(input: GlobalExceptionLogInput)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
import {
BNestGlobalExceptionLogWriter,
type GlobalExceptionLogInput,
} from "@bish-nest/core/exception-filters/global-exception-log-writer";
import { BNestPrismaService } from "@bish-nest/core/services";
import { SystemLogHttp500NotificationService } from "@api/shared/services/system-log-http500-notification.service";
import { Injectable } from "@nestjs/common";
@Injectable()
export class RecallAssessGlobalExceptionLogWriterService implements BNestGlobalExceptionLogWriter {
constructor(
private readonly prisma: BNestPrismaService,
private readonly http500Notification: SystemLogHttp500NotificationService,
) {}
async write(input: GlobalExceptionLogInput): Promise<void> {
const prismaAny = this.prisma.client as any;
if (!prismaAny?.systemLog?.create) return;
const created = await prismaAny.systemLog.create({
data: {
entity_type: "SYSTEM_MODULE",
operation_type: "INSERT",
request_endpoint: input.requestEndpoint,
request_method: input.requestMethod,
status_code: input.statusCode,
error_message: input.errorMessage,
ip_address: input.ipAddress,
user_agent: input.userAgent,
timestamp: new Date(),
},
});
if (input.statusCode === 500 && created?.id) {
void this.http500Notification.notifyForLogIds([created.id as number]).catch(() => {
// best-effort; never throw from log writer
});
}
}
}