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

Do not throw Forbidden error but log as warning #2383

Closed
nicoes opened this issue Sep 5, 2023 · 4 comments
Closed

Do not throw Forbidden error but log as warning #2383

nicoes opened this issue Sep 5, 2023 · 4 comments

Comments

@nicoes
Copy link

nicoes commented Sep 5, 2023

Is your feature request related to a problem? Please describe.
At the moment we are using Sentry for logging / monitoring Vendure errors. We see the Forbidden errors also being logged to Sentry.

Describe the solution you'd like
We could filter those errors out in Sentry but we think forbidden should not throw an error but can be logged as a warning instead, since it's expected behaviour.

Describe alternatives you've considered
Filtering Forbidden errors out in Sentry.

@martijnvdbrug
Copy link
Collaborator

Some extra context: UserInputError's are also logged as warning, and I feel ForbiddenError's are of similar importance: ForbiddenError usually means something is wrong with the user's credentials or permissions

@alexisvigoureux
Copy link
Contributor

Hi, we also use Sentry and we simply don't capture 'Forbidden' messages using an Apollo plugin. Check: https://beta-docs.vendure.io/reference/typescript-api/configuration/api-options/#apolloserverplugins

Here is an example of how to do it

export class ApolloLogs implements ApolloServerPlugin {
 public async requestDidStart(requestContext: GraphQLRequestContext): Promise<GraphQLRequestListener | void> {
    return {
      didEncounterErrors: async (context) => {
       // Maybe this line is not necessary for your app
        if (context.operation) {
          for (const err of context.errors) {
            if (err.extensions?.code === 'FORBIDDEN') {
              continue
            }

            ........
           Sentry.captureException(err) 
          }
        }
      },
    }
  }
}

@nicoes
Copy link
Author

nicoes commented Sep 5, 2023

Thanks for the alternative solution Alexis! That would be a good way to solve it if it were to remain an error. I agree with Martijn that a Forbidden error is a client induced error. Like the HTTP 403 Forbidden error. So from my perspective the server shouldn't throw an error in the first place. Hence this feature request.

@michaelbromley
Copy link
Member

Agreed. In v2.1 this should be downgraded to a warning.

michaelbromley added a commit that referenced this issue Sep 7, 2023
Closes #2383. Since this error occurs in expected circumstances, it should not be logged at the
error level.
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