in connected account, refresh-token can fail with network error (#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](https://github.com/twentyhq/twenty/pull/12233) that did not know all provider cases that can occur. Fixes https://github.com/twentyhq/twenty/issues/12589
This commit is contained in:
+1
@@ -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',
|
||||
}
|
||||
|
||||
+19
-2
@@ -93,9 +93,26 @@ export class ConnectedAccountRefreshTokensService {
|
||||
}
|
||||
} catch (error) {
|
||||
if (error?.name === 'AggregateError') {
|
||||
this.logger.log(error.message);
|
||||
this.logger.log(error.name);
|
||||
const firstErrorCode = error?.errors?.[0]?.code;
|
||||
const networkErrorCodes = [
|
||||
'ENETUNREACH',
|
||||
'ETIMEDOUT',
|
||||
'ECONNABORTED',
|
||||
'ERR_NETWORK',
|
||||
];
|
||||
const isTemporaryNetworkError =
|
||||
networkErrorCodes.includes(firstErrorCode);
|
||||
|
||||
this.logger.log(error?.message);
|
||||
this.logger.log(firstErrorCode);
|
||||
this.logger.log(error?.errors);
|
||||
|
||||
if (isTemporaryNetworkError) {
|
||||
throw new ConnectedAccountRefreshAccessTokenException(
|
||||
`Error refreshing tokens for connected account ${connectedAccount.id.slice(0, 7)} in workspace ${workspaceId.slice(0, 7)}: ${firstErrorCode}`,
|
||||
ConnectedAccountRefreshAccessTokenExceptionCode.TEMPORARY_NETWORK_ERROR,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.logger.log(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user