Better error handling in fetch data
This commit is contained in:
parent
1a2cdfd814
commit
d3cd6012e6
3 changed files with 17 additions and 21 deletions
|
|
@ -35,13 +35,6 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
|||
injector.map<String>((i) => store.state.serverUrl, key: "serverUrl");
|
||||
injector.map<String>((i) => store.state.gmapKey, key: "gmapKey");
|
||||
|
||||
/* VoidCallback mainFn = () {
|
||||
loadYourLocations().then((yl) {
|
||||
// Run baby run!
|
||||
|
||||
});
|
||||
}; */
|
||||
|
||||
var useSentry = !globals.isDevelopment;
|
||||
|
||||
SentryClient _sentry;
|
||||
|
|
@ -73,7 +66,8 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
|||
});
|
||||
}
|
||||
|
||||
Future<Null> _reportError(bool useSentry, SentryClient sentry, dynamic error, dynamic stackTrace) async {
|
||||
Future<Null> _reportError(bool useSentry, SentryClient sentry, dynamic error,
|
||||
dynamic stackTrace) async {
|
||||
// Print the exception to the console
|
||||
print('Caught error: $error');
|
||||
if (!useSentry) {
|
||||
|
|
@ -88,4 +82,3 @@ Future<Null> _reportError(bool useSentry, SentryClient sentry, dynamic error, dy
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,9 +47,10 @@ class FiresApi {
|
|||
final mobileToken = state.user.token;
|
||||
final String url = '${state
|
||||
.firesApiUrl}mobile/subscriptions/all/$apiKey/$mobileToken';
|
||||
// if (globals.isDevelopment) print('$url');
|
||||
return await resty.get(url).go().then((response) {
|
||||
if (response.statusCode == 200) {
|
||||
// print(response.body);
|
||||
// if (globals.isDevelopment) print(response.body);
|
||||
final dataSubscriptions =
|
||||
json.decode(response.body)['data']['subscriptions'];
|
||||
List<YourLocation> subscribed = [];
|
||||
|
|
|
|||
|
|
@ -149,13 +149,13 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
|
|||
|
||||
if (action is FetchYourLocationsAction) {
|
||||
// Use the api to fetch the YourLocations
|
||||
loadYourLocations().then((localLocations) {
|
||||
api
|
||||
.fetchYourLocations(store.state)
|
||||
.then((List<YourLocation> subscribedLocations) {
|
||||
// If it succeeds, dispatch a success action with the YourLocations.
|
||||
// Our reducer will then update the State using these YourLocations.
|
||||
// print('Subscribed to: ${subscribedLocations.length}');
|
||||
loadYourLocations().then((localLocations) {
|
||||
if (subscribedLocations is List) {
|
||||
// unsubscribe all locally to sync the subs state
|
||||
localLocations.forEach((location) => location.subscribed = false);
|
||||
|
|
@ -167,30 +167,32 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
|
|||
}).subscribed = true;
|
||||
});
|
||||
}
|
||||
|
||||
store.dispatch(new FetchYourLocationsSucceededAction(localLocations));
|
||||
persistYourLocations(localLocations);
|
||||
|
||||
localLocations.forEach((yl) {
|
||||
api
|
||||
.getFiresInLocation(
|
||||
state: store.state,
|
||||
lat: yl.lat,
|
||||
lon: yl.lon,
|
||||
distance: yl.distance)
|
||||
.then((value) {
|
||||
.getFiresInLocation(
|
||||
state: store.state,
|
||||
lat: yl.lat,
|
||||
lon: yl.lon,
|
||||
distance: yl.distance)
|
||||
.then((value) {
|
||||
yl.currentNumFires = value.numFires;
|
||||
store.dispatch(new UpdateYourLocationAction(yl));
|
||||
});
|
||||
});
|
||||
|
||||
store.dispatch(new FetchYourLocationsSucceededAction(localLocations));
|
||||
persistYourLocations(localLocations);
|
||||
Completer<Null> completer = action.refreshCallback;
|
||||
if (completer != null) {
|
||||
completer.complete(null);
|
||||
}
|
||||
});
|
||||
}).catchError((Exception error) {
|
||||
}).catchError((onError) {
|
||||
// If it fails, dispatch a failure action. The reducer will
|
||||
// update the state with the error.
|
||||
store.dispatch(new FetchYourLocationsFailedAction(error));
|
||||
store.dispatch(new FetchYourLocationsFailedAction(onError));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue