Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom exception does not work in SentryInterceptor #100

Open
kikefajardoh opened this issue Nov 15, 2022 · 4 comments
Open

Custom exception does not work in SentryInterceptor #100

kikefajardoh opened this issue Nov 15, 2022 · 4 comments

Comments

@kikefajardoh
Copy link

kikefajardoh commented Nov 15, 2022

Hello, I'm able to intercept exceptions using the example that exists in docs:

new SentryInterceptor({filters: [
    {
      type: HttpException,
      filter: (exception: HttpException) => {        
        return (500 > exception.getStatus());
      },
    }
]})

But when I try to track custom exception sentry interceptor does not work properly:

new SentryInterceptor({filters: [
    {
      type: CustomHttpException,
      filter: (exception: CustomHttpException) => {        
        return (exception.getLogInSentry());
      },
    }
]})

Another thing that I found is when I evaluate exception status it works:

new SentryInterceptor({filters: [
    {
      type: CustomHttpException,
      filter: (exception: CustomHttpException) => {        
        return (404 > exception.getStatus()); // 404 it's the current status of the exception
      },
    }
]})

This is the definition of CustomHttpException:

export class CustomHttpException extends HttpException {
    logInSentry: boolean;

    constructor(response: string | Record<string, any>, status: number, logInSentry = false) {
        super(response, status);
        this.logInSentry = logInSentry;
    }

    getLogInSentry(): boolean {
        return this.logInSentry;
    }
}
@daniel-tmp
Copy link

daniel-tmp commented Dec 9, 2022

I think that pr #95 is wrong.

I think
If filter option means filter OUT then original code is correct,
and if it means filter IN then not operator at 110 line must be removed.

@kikefajardoh
Copy link
Author

@daniel-tmp it's possible to revert this?

@rjurado01
Copy link

rjurado01 commented Feb 3, 2023

As it is now, if you have multiple filters, it always reported to Senty all errors because this code always returns true:

return filters.some(({ type, filter }) => {
  return !(exception instanceof type && (!filter || filter(exception)));
});

Example:

new SentryInterceptor({filters: [
    {
      type: HttpException,
      filter: (exception: HttpException) => {        
        return (500 > exception.getStatus());
      },
    },
    {
      type: MyCustomError
    }
]})
  • When throws exception = HttpException
  • exception instanceof MyCustomError = false
  • !(false && ...) = true
  • some([true, ....]) = true

It mus't be reverted to use every.

@gregoryorton-ws
Copy link

did this get reverted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants