Skip to content

in connected account, refresh-token can fail with network error #12815

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

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

guillim
Copy link
Contributor

@guillim guillim commented Jun 24, 2025

This PR fixes this issue from the connected account refresh token service that is

This PR fixes error handling in handleDriverException by ensuring that errors resembling MessageImportDriverException are correctly detected, even if they are plain objects and not true class instances. This prevents missed exception handling due to failed instanceof checks.

Was introduced by this PR that did not know all provider cases that can occur.

Fixes #12589

@guillim guillim self-assigned this Jun 24, 2025
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

Enhanced error handling in connected account token refresh operations and messaging import services to properly handle network errors and provider support issues.

  • Added TEMPORARY_NETWORK_ERROR to ConnectedAccountRefreshAccessTokenExceptionCode to properly categorize network failures during token refresh operations
  • Replaced instanceof MessageImportDriverException with 'code' in exception check to handle plain object errors
  • Added new PROVIDER_NOT_SUPPORTED error code to MessageImportDriverExceptionCode for better provider compatibility handling
  • Improved network error detection in ConnectedAccountRefreshTokensService by handling specific error codes (ENETUNREACH, ETIMEDOUT, etc.)
  • Enhanced error handling consistency by converting plain object errors to proper exception class instances

6 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile

@@ -13,4 +13,5 @@ export enum ConnectedAccountRefreshAccessTokenExceptionCode {
REFRESH_TOKEN_NOT_FOUND = 'REFRESH_TOKEN_NOT_FOUND',
REFRESH_ACCESS_TOKEN_FAILED = 'REFRESH_ACCESS_TOKEN_FAILED',
PROVIDER_NOT_SUPPORTED = 'PROVIDER_NOT_SUPPORTED',
TEMPORARY_NETWORK_ERROR = 'TEMPORARY_NETWORK_ERROR',
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Add a trailing comma after TEMPORARY_NETWORK_ERROR to maintain consistency with enum style and make future additions cleaner

Comment on lines +97 to +102
const networkErrorCodes = [
'ENETUNREACH',
'ETIMEDOUT',
'ECONNABORTED',
'ERR_NETWORK',
];
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 moving network error codes to a separate constant or enum for reusability across the codebase

Comment on lines +106 to 108
this.logger.log(error?.message);
this.logger.log(firstErrorCode);
this.logger.log(error?.errors);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Use structured logging with error object instead of multiple log calls. Consider: this.logger.log({ message: error?.message, code: firstErrorCode, errors: error?.errors })

Copy link
Contributor

📊 API Changes Report

REST API Changes

Summary

🔄 Changed Operations (63)

  • /apiKeys/duplicates: Modified operation
  • /attachments/duplicates: Modified operation
  • /blocklists/duplicates: Modified operation
  • /calendarChannelEventAssociations/duplicates: Modified operation
  • /calendarChannels/duplicates: Modified operation
  • /calendarEventParticipants/duplicates: Modified operation
  • /calendarEvents/duplicates: Modified operation
  • /companies/duplicates: Modified operation
  • /connectedAccounts/duplicates: Modified operation
  • /favoriteFolders/duplicates: Modified operation
  • /favorites/duplicates: Modified operation
  • /messageChannelMessageAssociations/duplicates: Modified operation
  • /messageChannels/duplicates: Modified operation
  • /messageFolders/duplicates: Modified operation
  • /messageParticipants/duplicates: Modified operation
  • /messages/duplicates: Modified operation
  • /messageThreads/duplicates: Modified operation
  • /notes/duplicates: Modified operation
  • /noteTargets/duplicates: Modified operation
  • /opportunities/duplicates: Modified operation
  • /people/duplicates: Modified operation
  • /pets/duplicates: Modified operation
  • /rockets/duplicates: Modified operation
  • /surveyResults/duplicates: Modified operation
  • /tasks/duplicates: Modified operation
  • /taskTargets/duplicates: Modified operation
  • /timelineActivities/duplicates: Modified operation
  • /viewFields/duplicates: Modified operation
  • /viewFilterGroups/duplicates: Modified operation
  • /viewFilters/duplicates: Modified operation
  • /viewGroups/duplicates: Modified operation
  • /views/duplicates: Modified operation
  • /viewSorts/duplicates: Modified operation
  • /webhooks/duplicates: Modified operation
  • /workflowAutomatedTriggers/duplicates: Modified operation
  • /workflowRuns/duplicates: Modified operation
  • /workflows/duplicates: Modified operation
  • /workflowVersions/duplicates: Modified operation
  • /workspaceMembers/duplicates: Modified operation
  • /apiKeys: Modified operation
  • /apiKeys/{id}: Modified operation
  • /calendarEvents: Modified operation
  • /calendarEvents/{id}: Modified operation
  • /companies: Modified operation
  • /companies/{id}: Modified operation
  • /opportunities: Modified operation
  • /opportunities/{id}: Modified operation
  • /people: Modified operation
  • /people/{id}: Modified operation
  • /pets: Modified operation
  • /pets/{id}: Modified operation
  • /viewFields: Modified operation
  • /viewFields/{id}: Modified operation
  • /viewFilters: Modified operation
  • /viewFilters/{id}: Modified operation
  • /viewGroups: Modified operation
  • /viewGroups/{id}: Modified operation
  • /views: Modified operation
  • /views/{id}: Modified operation
  • /viewSorts: Modified operation
  • /viewSorts/{id}: Modified operation
  • /workspaceMembers: Modified operation
  • /workspaceMembers/{id}: Modified operation

⚠️ Please review these API changes carefully before merging.

⚠️ Breaking Change Protocol

Breaking changes detected but PR title does not contain "breaking" - CI will pass but action needed.

🔄 Options:

  1. If this IS a breaking change: Add "breaking" to your PR title and add BREAKING CHANGE: to your commit message
  2. If this is NOT a breaking change: The API diff tool may have false positives - please review carefully

For breaking changes, add to commit message:

feat: add new API endpoint

BREAKING CHANGE: removed deprecated field from User schema

@@ -45,7 +45,7 @@ export class MessageImportExceptionHandlerService {
>,
workspaceId: string,
): Promise<void> {
if (exception instanceof MessageImportDriverException) {
if ('code' in exception) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

most important change to fix the issue

@charlesBochet charlesBochet merged commit 5c3550a into main Jun 24, 2025
42 checks passed
@charlesBochet charlesBochet deleted the connected-account-refresh-token-error branch June 24, 2025 11:51
Copy link
Contributor

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:28372

This environment will automatically shut down when the PR is closed or after 5 hours.

abdulrahmancodes pushed a commit to abdulrahmancodes/twenty that referenced this pull request Jun 26, 2025
…tyhq#12815)

This PR fixes this issue from the connected account refresh token
service that is

This PR fixes error handling in `handleDriverException` by ensuring that
errors resembling `MessageImportDriverException` are correctly detected,
even if they are plain objects and not true class instances. This
prevents missed exception handling due to failed `instanceof` checks.

Was introduced by [this
PR](twentyhq#12233) that did not know all
provider cases that can occur.

Fixes twentyhq#12589
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.

Error: Error refreshing tokens for connected account 26f9a187-345d-4268-9275-2f25b7aac6a8 in workspace af8dc545-11cc-4fad-8a3b-633bc32e2c66: undefined
2 participants