Are you looking to customize error responses in NestJS guards
?
import { CanActivate, Injectable, ExecutionContext, NotFoundException } from '@nestjs/common';
import { Observable } from 'rxjs';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { UserParamsNotFoundException } from 'src/statusResponse/error.response';
@Injectable()
export class UserGuard implements CanActivate {
constructor(
@InjectModel(Users.name) private userModel: Model<CreateUser>,
) {}
async canActivate(
context: ExecutionContext,
): Promise<any> {
const request = context.switchToHttp().getRequest();
const { user, } = request.body; // Extract keys using object destructuring.
const isUserExist: boolean = function (); // Function returning true or false based on conditions.
return isUserExist ? true : false;
}
};