Skip to content

Commit

Permalink
feat: support graphql
Browse files Browse the repository at this point in the history
This is the code by @chasevida from digikare#47
  • Loading branch information
roderik authored Aug 24, 2021
1 parent 3cd3d21 commit 2dc7535
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions lib/prom-catch-all.exception-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GqlContextType>() === '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)
}
}
}
}

0 comments on commit 2dc7535

Please sign in to comment.