dreampowder / strava_flutter

Flutter package to use Strava v3 API
Other
37 stars 52 forks source link

Exception not catched #75

Closed harkairt closed 2 years ago

harkairt commented 2 years ago

How do I catch if some error happens?

I have the following code

final stravaClient = StravaClient(secret: '...', clientId: '...');
try {
  final activity = await stravaClient.activities.getActivity(6172408801);
  debugPrint('__________Response: ${activity.name}');
} on Exception catch (e) {
  debugPrint('__________Exception: $e');
} on Error catch (e) {
  debugPrint('__________Error: $e');
}

I'd expect to catch some exception here, as I haven't authenticated yet. None of the debugPrints appear, but this does from the package:

E/flutter (22386): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Instance of 'Fault'
E/flutter (22386): 

.. if I authenticated then I do get back an activity.

dreampowder commented 2 years ago

hello , sorry for late response, you can catch the error by adding:

on Fault catch(e){
  debugPrint('caught fault')
}

My initial thought was to return all errors as 'Fault' from the package, but I guess there are cases that I missed implementing