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

Dio fetch can't catch error #2271

Closed
bemilyswom opened this issue Jul 17, 2024 · 1 comment
Closed

Dio fetch can't catch error #2271

bemilyswom opened this issue Jul 17, 2024 · 1 comment

Comments

@bemilyswom
Copy link

bemilyswom commented Jul 17, 2024

Package

dio

Version

5.5.0+1

Operating-System

Android, iOS

Adapter

Default Dio

Output of flutter doctor -v

[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale ko-KR)
    • Flutter version 3.22.2 on channel stable at /Users/swom/Flutter/SDK/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (6주 전), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/swom/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/swom/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.91.1)
    • VS Code at /Users/swom/Flutter/tools/Visual Studio Code.app/Contents
    • Flutter extension version 3.92.0

Dart Version

3.4.3

Steps to Reproduce

  1. Token expiration
  2. After receive a new token, retry the API (dio.fetch)
  3. The api throws an error but fails to catch it as DioException.

Expected Result

If an error occurs in the API retried through dio.fetch, it must catch it immediately.
If I set a delay, It catch sometime the error later.

Actual Result

  @override
  void onError(DioException err, ErrorInterceptorHandler handler) async {
    int statusCode = err.response?.statusCode ?? 0;
    RequestOptions errorRequestOptions = err.requestOptions;

    debugPrint('BFDioAuthInterceptor - onError : $statusCode');

    if (statusCode == 401) {
      // Token Expired
      String newToken = await BFPreferences.shared.getAccessToken();

      try {
        RequestOptions errorNewOptions = errorRequestOptions;
        errorNewOptions.headers['Authorization'] = 'Bearer $newToken';

        final response = await dio.fetch(errorNewOptions);
        return handler.resolve(response);
      } on DioException catch (e) {
        return handler.reject(e);
      }
    }
    return handler.reject(err);
  }
@bemilyswom bemilyswom added h: need triage This issue needs to be categorized s: bug Something isn't working labels Jul 17, 2024
@AlexV525
Copy link
Member

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2024
@AlexV525 AlexV525 added i: not reading documents and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants