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

Unable to catch TimeoutException when using flutter retry package #49

Closed
briankariuki opened this issue Oct 14, 2020 · 1 comment
Closed

Comments

@briankariuki
Copy link

I'm wrapping my request to an api endpoint using the flutter retry package to retry the call if on socket exception or timeout exception. On timeout the Requests package throws a Timeout Exception that is not caught by the retry package and also in a try catch block it fails. Anyone have an idea why this is not working? Tried setting the timeout to about 20 seconds, same issue.

Future getPlayerElementSummary(int playerId) async {
try {
var playerElementSummaryUrl = baseUrl + '/element-summary/$playerId/';
var cookies =
await Requests.getStoredCookies(Requests.getHostname(loginUrl));
Requests.setStoredCookies(
Requests.getHostname(playerElementSummaryUrl), cookies);

  final response = await retry(
    () async {
      try {
        var data = await Requests.get(playerElementSummaryUrl,
            headers: head, timeoutSeconds: 20);
        return data.json();
      } catch (e) {
        print(e);
      }
    },
    retryIf: (e) => e is SocketException || e is TimeoutException,
  );
  return response;
} catch (e) {
  print(e);
}

}

Flutter doctor logs
` [√] Flutter (Channel stable, 1.20.1, on Microsoft Windows [Version 10.0.18362.900], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.50.0)
[√] Connected device (1 available)

• No issues found!`

@briankariuki
Copy link
Author

Just realised its an issue with the debugger, it catches all exceptions even handled ones. Closing this issue now

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

1 participant