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

when using "handler.reject(error);" in onError of interceptors, I cannot DioException in .catchError(), but find it in .then(). #2273

Closed
deidei1231 opened this issue Jul 24, 2024 · 2 comments

Comments

@deidei1231
Copy link

deidei1231 commented Jul 24, 2024

Package

dio

Version

5.5.0+1

Operating-System

Android, Web

Adapter

Default Dio

Output of flutter doctor -v

[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [版本 10.0.22631.3880], locale zh-CN)
    • Flutter version 3.22.2 on channel stable at D:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (7 weeks ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\14732\AppData\Local\Android\sdk
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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--11609105)

[√] Connected device (3 available)
    • XIAOMI(mobile)    • 192.168.1.209:8888 • android-arm64  • Android 12 (API 32)
    • Windows (desktop) • windows            • windows-x64    • Microsoft Windows [版本 10.0.22631.3880]
    • Edge (web)        • edge               • web-javascript • Microsoft Edge 126.0.2592.113

Dart Version

No response

Steps to Reproduce

// in dio_request.dart
_dio.interceptors.add(
InterceptorsWrapper(
onRequest: (RequestOptions options, RequestInterceptorHandler handler) {
return handler.next(options);
},
onResponse: (Response response, ResponseInterceptorHandler handler) {
print(1111);
return handler.next(response);
},
onError: (DioException error, ErrorInterceptorHandler handler) {
print(2222);
return handler.reject(error);
},
),
);

// in login.dart
await Request().request("/login", method: DioMethod.post, data: {
"account": data['username'],
"password": data['password'],
}).then((res){
print(3333);
print(response is DioException); // the actual result is ture
}).catchError((e){
print(4444);
print(e);
});

Expected Result

when I write "return handler.reject(error);" in onError of interceptors, I can find the DioException in ".catchError()",
When the error.response,statuscode returned by the server is 400, the print execution order: 2222 4444

Actual Result

when I write "return handler.reject(error);" in onError of interceptors, I can find the DioException in ".then()".
The print execution order: 2222 1111

@deidei1231 deidei1231 added h: need triage This issue needs to be categorized s: bug Something isn't working labels Jul 24, 2024
@AlexV525
Copy link
Member

Please provide a minimal reproducible example.

@AlexV525 AlexV525 added the h: need more info Further information is requested label Jul 31, 2024
@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2024
@AlexV525 AlexV525 added i: no response and removed h: need more info Further information is requested h: need triage This issue needs to be categorized s: bug Something isn't working labels Oct 7, 2024
@deidei1231

This comment was marked as off-topic.

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