- add ScenarioRunLogEntity to persist step script output to DB - stepLogger dual-writes to NestJS logger and DB (fire-and-forget) - add GET /scenarios/:id/run/:runId returning run, stepRuns and logs - add POST /scenarios/:id/run/:runId/wait (polls until terminal state) - 9 new integration tests for the two endpoints (136 total) - add eslint with typescript-eslint and eslint-config-prettier - add npm scripts: format, lint, lint:fix - resolve all lint errors across src and test (no any types) - add CONTRIBUTING.md covering dev workflow
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import {
|
|
ArgumentsHost,
|
|
BadRequestException,
|
|
Catch,
|
|
ExceptionFilter,
|
|
HttpException,
|
|
InternalServerErrorException,
|
|
} from "@nestjs/common";
|
|
import { TraceLogger } from "../common/trace-logger";
|
|
import type { Request, Response } from "express";
|
|
|
|
@Catch(BadRequestException, InternalServerErrorException)
|
|
export class HttpExceptionFilter implements ExceptionFilter {
|
|
private readonly logger = new TraceLogger(HttpExceptionFilter.name);
|
|
|
|
catch(exception: HttpException, host: ArgumentsHost): void {
|
|
const ctx = host.switchToHttp();
|
|
const request = ctx.getRequest<Request>();
|
|
const response = ctx.getResponse<Response>();
|
|
const status = exception.getStatus();
|
|
const body = exception.getResponse();
|
|
|
|
const cause = (exception as unknown as { cause?: Error }).cause;
|
|
const causeMessage = cause ? ` | cause: ${cause.message}` : "";
|
|
const message = `${exception.message}${causeMessage}`;
|
|
|
|
if (status >= 500) {
|
|
this.logger.error(
|
|
`[${request.method} ${request.url}] ${status} — ${message}`,
|
|
cause?.stack ?? exception.stack,
|
|
);
|
|
} else {
|
|
this.logger.warn(
|
|
`[${request.method} ${request.url}] ${status} — ${message}`,
|
|
);
|
|
}
|
|
|
|
response.status(status).json(body);
|
|
}
|
|
}
|