Skip to content

Commit

Permalink
feat(view_models): added stackTrace to onError callback for FutureVie…
Browse files Browse the repository at this point in the history
…wModel and StreamViewModel
  • Loading branch information
Pebkac03 committed Jan 4, 2025
1 parent 5b6e772 commit fbd509c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/src/view_models/data_models/single_data_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ abstract class FutureViewModel<T> extends DynamicSourceViewModel<T>
setMessage(null);
setBusy(true);

data = await runBusyFuture<T?>(futureToRun(), throwException: true)
.catchError((error) {
try {
data = await runBusyFuture<T?>(futureToRun(), throwException: true);
} catch (exception, stackTrace) {
setError(error);
setBusy(false);
onError(error);
onError(exception, stackTrace);

notifyListeners();
if (rethrowException) {
throw error;
}

return null;
});
}

if (data != null) {
onData(data);
Expand All @@ -50,7 +51,7 @@ abstract class FutureViewModel<T> extends DynamicSourceViewModel<T>
}

/// Called when an error occurs within the future being run
void onError(error) {}
void onError(dynamic error, StackTrace? stackTrace) {}

/// Called after the data has been set
void onData(T? data) {}
Expand Down Expand Up @@ -101,10 +102,10 @@ abstract class StreamViewModel<T> extends DynamicSourceViewModel<T>
onData(data);
notifyListeners();
},
onError: (error) {
onError: (dynamic error, StackTrace? stackTrace) {
setError(error);
data = null;
onError(error);
onError(error, stackTrace);
notifyListeners();
},
);
Expand All @@ -120,7 +121,7 @@ abstract class StreamViewModel<T> extends DynamicSourceViewModel<T>
void onSubscribed() {}

/// Called when an error is fired in the stream
void onError(error) {}
void onError(Object error, StackTrace? stackTrace) {}

void onCancel() {}

Expand Down

0 comments on commit fbd509c

Please sign in to comment.