we are using GQL and have a global exception filter , we would like to change the status code of the replies to 4xx instead of 200 with error message.
how can we change the status code ?
following code works , but throws this warning:
UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at ServerResponse.setHeader
export class ExceptionsFilter
extends BaseExceptionFilter
implements GqlExceptionFilter
{
public catch(exception: unknown, host: ArgumentsHost): void {
const gqlHost = GqlArgumentsHost.create(host);
const response = gqlHost.getContext().res;
if (exception instanceof HttpException)
response.status(400).json({
statusCode: 400,
message: exception.getResponse(),
});