| Index: pkg/shelf/lib/src/util.dart
|
| diff --git a/pkg/shelf/lib/src/util.dart b/pkg/shelf/lib/src/util.dart
|
| index ee761d635a77cc824d0d1054c360c6bac1e2989f..43f7238910aec1b91e38370fa37b8ef143307855 100644
|
| --- a/pkg/shelf/lib/src/util.dart
|
| +++ b/pkg/shelf/lib/src/util.dart
|
| @@ -10,3 +10,16 @@ import 'package:stack_trace/stack_trace.dart';
|
|
|
| /// Like [Future.sync], but wraps the Future in [Chain.track] as well.
|
| Future syncFuture(callback()) => Chain.track(new Future.sync(callback));
|
| +
|
| +/// Run [callback] and capture any errors that would otherwise be top-leveled.
|
| +///
|
| +/// If [this] is called in a non-root error zone, it will just run [callback]
|
| +/// and return the result. Otherwise, it will capture any errors using
|
| +/// [runZoned] and pass them to [onError].
|
| +catchTopLevelErrors(callback(), void onError(error, StackTrace stackTrace)) {
|
| + if (Zone.current.inSameErrorZone(Zone.ROOT)) {
|
| + return runZoned(callback, onError: onError);
|
| + } else {
|
| + return callback();
|
| + }
|
| +}
|
|
|