nest-raven icon indicating copy to clipboard operation
nest-raven copied to clipboard

Sentry does not trigger in AuthGuards' strategy

Open bendadaniel opened this issue 2 years ago • 1 comments

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

bendadaniel avatar Nov 11 '22 14:11 bendadaniel

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

mentos1386 avatar Nov 11 '22 15:11 mentos1386