Skip to content

TF-3833 Fix failed to keep mobile app connect after network issue #3886

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

Conversation

dab246
Copy link
Member

@dab246 dab246 commented Jul 18, 2025

Issue

#3833

Reproduce

Screen.Recording.2025-07-18.at.01.37.16.mov

Root cause

We are using the flutter_appauth library to authenticate the account, get the token and refresh the token. This flow does not use Dio with the app, which results in the flutter_appauth library's refreshToken returning a 500 error, but we ignore it because it is not a DioError. So the 401 error from the request using the expired token is still returned.

Solution

We will catch the 500 error from flutter_appauth and handle it

Dependency

Resolved

  • Mobile:
demo.online-video-cutter.com.mp4
  • Web:
demo-web.mov

Copy link

This PR has been deployed to https://linagora.github.io/tmail-flutter/3886.

@hoangdat
Copy link
Member

hoangdat commented Jul 30, 2025

  • Still be log out when get server error
I/flutter ( 3701): [TwakeMail] [ERROR] AuthenticationClientMobile::refreshingTokensOIDC(): PlatformException(server_error, null, null, null)
I/flutter ( 3701): [TwakeMail] [ERROR] AuthenticationClientMobile::handleException: ErrorDetails = FlutterAppAuthPlatformErrorDetails(type: null,
I/flutter ( 3701):  code: null,
I/flutter ( 3701):  error: null,
I/flutter ( 3701):  errorDescription: null,
I/flutter ( 3701):  errorUri: null,
I/flutter ( 3701):  domain null,
I/flutter ( 3701): rootCauseDebugDescription: null,
I/flutter ( 3701):  errorDebugDescription: null)
I/flutter ( 3701): [TwakeMail] [ERROR] AuthorizationInterceptors::onError:Exception: PlatformException(server_error, null, null, null)
I/flutter ( 3701): *** DioError ***:
I/flutter ( 3701): uri: https://jmap.lin-saas.dev/jmap
I/flutter ( 3701): DioError [bad response]: The request returned an invalid status code of 401.
I/flutter ( 3701): Error: PlatformException(server_error, null, null, null)
I/flutter ( 3701): uri: https://jmap.lin-saas.dev/jmap
I/flutter ( 3701): statusCode: 401
I/flutter ( 3701): headers:
I/flutter ( 3701):  connection: keep-alive
I/flutter ( 3701):  access-control-allow-headers: Content-Type, Authorization, Accept
I/flutter ( 3701):  date: Wed, 30 Jul 2025 11:26:48 GMT
I/flutter ( 3701):  access-control-allow-origin: *
I/flutter ( 3701):  access-control-allow-methods: GET, POST, OPTIONS
I/flutter ( 3701):  strict-transport-security: max-age=31536000; includeSubDomains
I/flutter ( 3701):  content-length: 60
I/flutter ( 3701):  access-control-max-age: 86400
I/flutter ( 3701):  content-type: application/json
I/flutter ( 3701): 
I/flutter ( 3701): 
I/flutter ( 3701): [TwakeMail] [ERROR] RemoteExceptionThrower::throwException():error: DioError [bad response]: The request returned an invalid status code of 401.
I/flutter ( 3701): Error: PlatformException(server_error, null, null, null) | stackTrace: #0      DioMixin.fetch.<anonymous closure> (package:dio/src/dio_mixin.dart:530:7)
I/flutter ( 3701): #1      _rootRunBinary (dart:async/zone.dart:1423:47)
I/flutter ( 3701): #2      _CustomZone.runBinary (dart:async/zone.dart:1315:19)
I/flutter ( 3701): #3      _FutureListener.handleError (dart:async/future_impl.dart:178:22)
I/flutter ( 3701): #4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:873:47)
I/flutter ( 3701): #5      Future._propagateToListeners (dart:async/future_impl.dart:894:13)
I/flutter ( 3701): #6      Future._completeError (dart:async/future_impl.dart:674:5)
I/flutter ( 3701): #7      _SyncCompleter._completeError (dart:async/future_impl.dart:63:12)
I/flutter ( 3701): #8      _Completer.completeError (dart:async/future_impl.dart:27:5)
I/flutter ( 3701): #9      Future.any.onError (dart:async/future.dart:633:45)
I/flutter ( 3701): #10     _rootRunBinary (dart:async/zone.dart:1423:47)
I/flutter ( 3701): #11     _CustomZone.runBinary (dart:async/zone.dart:1315
I/flutter ( 3701): [TwakeMail] [ERROR] RemoteExceptionThrower::throwException():type: DioErrorType.badResponse | response: {"type":"about:blank","status":401,"detail":"Expired token"} | error: PlatformException(server_error, null, null, null)
I/flutter ( 3701): [TwakeMail] SingleEmailController::onDataFailureViewState:failure = MarkAsEmailReadFailure
I/flutter ( 3701): [TwakeMail] [ERROR] SingleEmailController::handleUrgentExceptionOnMobile():Failure: MarkAsEmailReadFailure(ReadActions.markAsRead, BadCredentialsException(Bad credentials, null), null) | Exception: BadCredentialsException(Bad credentials, null)
I/flutter ( 3701): [TwakeMail] SingleEmailController::handleBadCredentialsException:
I/flutter ( 3701): [TwakeMail] SingleEmailController::clearDataAndGoToLoginPage:

@dab246
Copy link
Member Author

dab246 commented Jul 30, 2025

  • Still be log out when get server error

The error value you are testing is NULL so we can't determine the error is 500. Hardcode the exact exception and it will work.

I/flutter ( 3701): [TwakeMail] [ERROR] AuthenticationClientMobile::handleException: ErrorDetails = FlutterAppAuthPlatformErrorDetails(type: null,
I/flutter ( 3701):  code: null,
I/flutter ( 3701):  error: null,
I/flutter ( 3701):  errorDescription: null,
I/flutter ( 3701):  errorUri: null,
I/flutter ( 3701):  domain null,
I/flutter ( 3701): rootCauseDebugDescription: null,
I/flutter ( 3701):  errorDebugDescription: null)

@dab246 dab246 requested a review from hoangdat July 30, 2025 12:32
@hoangdat hoangdat merged commit d4a56af into master Aug 14, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants