Is there a way to achieve a status of 200
and stop the controller call if a certain key in the request payload meets my criteria?
I've implemented Interceptors in my application, but I'm struggling to send a status of "200" without causing an exception.
For instance:
@Injectable()
export class MyInterceptor implements NestInterceptor {
intercept(
context: ExecutionContext,
next: CallHandler<any>,
): Observable<any> | Promise<Observable<any>> {
const { data } = context.switchToHttp().getRequest().body as Message;
const payload: InputData = JSON.parse(data.toString());
if (payload.order.payment.type === 'MY_SPECIFIC_VALUE') {
// How can I return a success response and halt the controller call?
throw new HttpException(
{
message:
'payment type is not supported, this message will be ignored.',
},
200,
);
}
return next.handle();
}
}