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

[IOS] interceptor onError is not triggered only when losing connectivity #426

Closed
amrosama2020 opened this issue Aug 20, 2019 · 5 comments
Closed

Comments

@amrosama2020
Copy link

New Issue Checklist

  • [Yes] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name ios
Platform Version All
Dio Version 2.1.13
Android Studio / Xcode Version Xcode 10.2.1
Repro rate all the time (100%)
Repro with our demo prj Can't reproduce because response is too fast
Demo project link Can prepare it

Issue Description and Steps

Issue is that the interceptor onError doesn't trigger in IOS in the following scenario:

  1. initiate a slow request
  2. disable/lose connectivity (e.g. close mobile network)

Interceptor onRequest, onResponse, and onError normally work with regular scenarios on all platforms, but in IOS onError is not triggered only when losing connectivity after sending the request.

Interceptor is setup like this:

var client = Dio();
    client.interceptors
        .add(InterceptorsWrapper(onError: (DioError e) {
      // Do something with response error
      // if (e.error is HttpException || e.error is SocketException)
      //   e.message = "Connection Failed, Please check your internet connection";
      return e; //continue
    }));

I tried placing breakpoints in all catch statements in dio library but none fire on losing connection.

@zk-luke
Copy link

zk-luke commented Aug 21, 2019

I have encountered a similar problem to you.
The interceptor can not intercept DioErrorType.CANCEL either.
For now, I solve the problem like this:

try {
      Response res = await _dio.request(
        path,
        data: data,
        queryParameters: queryParameters,
        options: Options(method: method),
      );
      return res.data;
    } catch (e) {
	
      //if e.type == DioErrorType.CONNECT_TIMEOUT
      //you can handle the error at here
      
      return {};
    }

@bishopmorton
Copy link

in adapter.dart.
it makes sense to work around all awaits, not only _httpClient.openUrl...

await request.addStream(requestStream).timeout(Duration(milliseconds:options.connectTimeout));
}

HttpClientResponse responseStream = await request.close().timeout(Duration(milliseconds:options.connectTimeout));

^^^ it helps on iOS to finally start getting connect timeouts

@amrosama2020
Copy link
Author

I ended up adding a timeout but still users with disconnected network will have to wait for the timeout to finish before getting an error.

@stale
Copy link

stale bot commented Oct 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Oct 11, 2019
@stale stale bot closed this as completed Oct 18, 2019
@quantela-ashutosh
Copy link

Still facing this issue.

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

No branches or pull requests

4 participants