nest-raven
nest-raven copied to clipboard
Sentry does not trigger in AuthGuards' strategy
Hello, my sentry implementation work fine except one situation.
I am using on controller's routes Auth guard with custom strategy @UseGuards(LocalAuthGuard)
LocalAuthGuard strategy is simple class (local.strategy.ts):
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super();
}
async validate(username: string, password: string): Promise<User | false>
{
throw new Error("sentry test error"); //!!!!!!!!!!!!!!!!!!!!!!!!!!
let user = await this.authService.validateUserByPassword(username, password);
if (!user)
return false;
return user;
}
}
when I throw error in function validate(), setry will not catch it..
Do you know where could be problem or is it normal?
Thank you Daniel
Hm, i think it's due to Guards being triggered before Interceptors[1]. We are using Interceptors to capture exceptions.
Not sure what the correct "fix" would be for this. Maybe we should introduce a "SentryExceptionFilter", which gets triggered by errors thrown in Guards[2].
[1] https://docs.nestjs.com/guards [2] https://docs.nestjs.com/exception-filters