diff --git a/lib/prom-catch-all.exception-filter.ts b/lib/prom-catch-all.exception-filter.ts index 741944b..9893761 100644 --- a/lib/prom-catch-all.exception-filter.ts +++ b/lib/prom-catch-all.exception-filter.ts @@ -37,20 +37,35 @@ export class PromCatchAllExceptionsFilter extends BaseExceptionFilter { exception: unknown, host: ArgumentsHost, ) { - const ctx = host.switchToHttp(); - const request = ctx.getRequest(); - const status = - exception instanceof HttpException - ? exception.getStatus() - : HttpStatus.INTERNAL_SERVER_ERROR; + const isGraphQLRequest = host.getType() === 'graphql' - const path = normalizePath(getBaseUrl(request.baseUrl || request.url), [], "#val"); + const request = isGraphQLRequest + ? GqlExecutionContext.create(host as ExecutionContext).getContext()?.req + : host.switchToHttp().getRequest() + const baseUrl = request?.baseUrl || request?.originalUrl || request?.url || '/' + const method = isGraphQLRequest + ? request?.method || 'POST' + : request?.method + + const status = exception instanceof HttpException + ? exception.getStatus() + : HttpStatus.INTERNAL_SERVER_ERROR + + const path = normalizePath( + getBaseUrl(baseUrl), + [], + '#val', + ) + this._counter.inc({ - method: request.method, + method, path, status, - }); - super.catch(exception, host); + }) + + if ( ! isGraphQLRequest) { + super.catch(exception, host) + } } -} \ No newline at end of file +}