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

Fix:If attachment token expires, it throws a 500 error instead of Unauthenticated #8939

Closed
wants to merge 1 commit into from

Conversation

giiger
Copy link

@giiger giiger commented Dec 6, 2024

This fixes this issue by throwing a descriptive error instead of a server error 500

…uthenticated

This fixes this issue by throwing a descriptive error instead of a server error 500
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Implements a new ExpiredAttachmentTokenError class to handle expired attachment tokens with proper 401 Unauthorized responses instead of 500 Internal Server Error.

  • Added ExpiredAttachmentTokenError class in /packages/twenty-server/src/engine/core-modules/graphql/utils/graphql-errors.util.ts
  • Missing name property definition in ExpiredAttachmentTokenError class unlike other error classes
  • Error class not added to graphQLPredefinedExceptions mapping in /packages/twenty-server/src/engine/utils/global-exception-handler.util.ts
  • Modified convertHttpExceptionToGraphql function to handle expired token messages

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

2 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +195 to +198
export class ExpiredAttachmentTokenError extends BaseGraphQLError {
constructor(message = 'The attachment token has expired') {
super(message, ErrorCode.UNAUTHENTICATED);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Missing Object.defineProperty(this, 'name', { value: 'ExpiredAttachmentTokenError' }); to match pattern of other error classes

Comment on lines +196 to +197
constructor(message = 'The attachment token has expired') {
super(message, ErrorCode.UNAUTHENTICATED);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider reusing AuthenticationError since this is using the same UNAUTHENTICATED code, or document why a separate class is needed

Comment on lines +110 to +112
} else if (message.includes('attachment token expired')) {
// Check if the error message indicates an expired attachment token
error = new ExpiredAttachmentTokenError(message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: String matching on error messages is fragile. Consider using a specific error code or type instead.

// Check if the error message indicates an expired attachment token
error = new ExpiredAttachmentTokenError(message);
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Extra whitespace before else clause breaks consistency with the rest of the file

Copy link

github-actions bot commented Dec 6, 2024

Welcome!

Hello there, congrats on your first PR! We're excited to have you contributing to this project.
By submitting your Pull Request, you acknowledge that you agree with the terms of our Contributor License Agreement.

Generated by 🚫 dangerJS against 1d5bd36

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giiger Thanks for opening a PR, I agree we should improve error handling.

  1. About the functional behavior: I'm a bit surprise this has to deal with graphql errors. To me files are serve over controllers (file.controller.ts) and I don't see what it has to do with controllers.

  2. About the strategy: For rest controllers and for GraphQL API, we want to keep the number of possible errors low (here we should re-use the Authentication error I think) but have a flexible message which is already currently possible. We want services (here token validation service) to throw business specific errors (with dedicated error_code) and then the caller here (a rest controller to convert it to a more standard exception)

Let's first discuss 1) could you help me understand why this has to deal with GraphQL, I'm a bit lost

@giiger
Copy link
Author

giiger commented Dec 8, 2024

Yes, I apologize I am new to contributing on open source and I am not too familiar with the file structure or the code norms of this project. I see your point about the separation between controllers and GraphQL, and I may have misunderstood how the error handling should be implemented in this context.

Could you possibly give me some guidance about my next steps I should take? I would like to continue working towards dealing with error handling

@charlesBochet
Copy link
Member

@giiger sure ! First:

  • does your existing PR solve the issue, could you show me how? (before / after behavior)

@charlesBochet
Copy link
Member

@giiger I'm going to close this PR as it's staled, feel free to re-open it if you still want to work on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants