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 custom errors thrown as 500 #6238

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

Weiko
Copy link
Member

@Weiko Weiko commented Jul 12, 2024

We call convertExceptionToGraphQLError in the exception handler for http exceptions but we don't take into account those that already are graphqlErrors and because of that the logic of convertExceptionToGraphql is to fallback to a 500.
Now if the exception is a BaseGraphqlError (custom graphql error we throw in the code), we throw them directly.

BEFORE
Screenshot 2024-07-12 at 15 33 03

AFTER
Screenshot 2024-07-12 at 15 32 01

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

  • Updated packages/twenty-server/src/engine/utils/global-exception-handler.util.ts to handle BaseGraphQLError directly.
  • Prevented fallback to HTTP 500 for custom GraphQL errors.
  • Ensured custom GraphQL errors return intended status codes.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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

(updates since last review)

  • Excluded 'Link' field type in StyledSettingsObjectFieldTypeSelect in /packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx
  • Uncommented 'Link' field type in exclusion list in /packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldStep2.tsx
  • Added validation to deprecate 'LINK' field types in /packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.service.ts
  • Reordered imports for better organization in /packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.service.ts

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@charlesBochet charlesBochet merged commit 1dff5bf into main Jul 12, 2024
6 checks passed
@charlesBochet charlesBochet deleted the c--fix-graphql-exception-thrown-as-500 branch July 12, 2024 15:56
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

(updates since last review)

  • Replaced useExceptionHandler with useGraphQLErrorHandlerHook in /packages/twenty-server/src/engine/api/graphql/metadata.module-factory.ts
  • Introduced EngineGraphQLModule in /packages/twenty-server/src/engine/core-modules/graphql/engine-graphql.module.ts
  • Added useGraphQLErrorHandlerHook in /packages/twenty-server/src/engine/core-modules/graphql/hooks/use-graphql-error-handler.hook.ts
  • Added generateGraphQLErrorFromError utility in /packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts
  • Updated exception handling logic across multiple files to prevent custom GraphQL errors from defaulting to 500 errors

16 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

graphqlError.extensions['response'] = error.message;
}

return error;
Copy link
Contributor

Choose a reason for hiding this comment

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

🧠 logic: Should return graphqlError instead of error to ensure the converted error is returned.

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

Successfully merging this pull request may close these issues.

3 participants