diff --git a/dio/CHANGELOG.md b/dio/CHANGELOG.md index eaaea9dee..8ba26205a 100644 --- a/dio/CHANGELOG.md +++ b/dio/CHANGELOG.md @@ -5,7 +5,7 @@ See the [Migration Guide][] for the complete breaking changes list.** ## Unreleased -*None.* +- Revert "Catch sync/async exceptions in interceptors' handlers". ## 5.4.2 diff --git a/dio/lib/src/dio_mixin.dart b/dio/lib/src/dio_mixin.dart index 9c5507b36..af057a7dc 100644 --- a/dio/lib/src/dio_mixin.dart +++ b/dio/lib/src/dio_mixin.dart @@ -338,7 +338,7 @@ abstract class DioMixin implements Dio { Options? options, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress, - }) async { + }) { final requestOptions = (options ?? Options()).compose( this.options, path, @@ -377,17 +377,14 @@ abstract class DioMixin implements Dio { FutureOr Function(dynamic) requestInterceptorWrapper( InterceptorSendCallback cb, ) { - return (dynamic incomingState) async { + return (dynamic incomingState) { final state = incomingState as InterceptorState; if (state.type == InterceptorResultType.next) { return listenCancelForAsyncTask( requestOptions.cancelToken, Future(() async { final handler = RequestInterceptorHandler(); - final callback = cb(state.data as RequestOptions, handler); - if (callback is Future) { - await callback; - } + cb(state.data as RequestOptions, handler); return handler.future; }), ); @@ -401,7 +398,7 @@ abstract class DioMixin implements Dio { FutureOr Function(dynamic) responseInterceptorWrapper( InterceptorSuccessCallback cb, ) { - return (dynamic incomingState) async { + return (dynamic incomingState) { final state = incomingState as InterceptorState; if (state.type == InterceptorResultType.next || state.type == InterceptorResultType.resolveCallFollowing) { @@ -409,16 +406,12 @@ abstract class DioMixin implements Dio { requestOptions.cancelToken, Future(() async { final handler = ResponseInterceptorHandler(); - final callback = cb(state.data as Response, handler); - if (callback is Future) { - await callback; - } + cb(state.data as Response, handler); return handler.future; }), ); - } else { - return state; } + return state; }; } @@ -427,16 +420,13 @@ abstract class DioMixin implements Dio { FutureOr Function(Object) errorInterceptorWrapper( InterceptorErrorCallback cb, ) { - return (error) { + return (dynamic error) { final state = error is InterceptorState ? error : InterceptorState(assureDioException(error, requestOptions)); Future handleError() async { final handler = ErrorInterceptorHandler(); - final callback = cb(state.data, handler); - if (callback is Future) { - await callback; - } + cb(state.data, handler); return handler.future; } @@ -689,10 +679,10 @@ abstract class DioMixin implements Dio { CancelToken? cancelToken, Future future, ) { - return Future.any([ - if (cancelToken != null) cancelToken.whenCancel.then((e) => throw e), - future, - ]); + if (cancelToken == null) { + return future; + } + return Future.any([future, cancelToken.whenCancel.then((e) => throw e)]); } @internal diff --git a/dio/lib/src/interceptor.dart b/dio/lib/src/interceptor.dart index 9ce9f6124..a062ebb28 100644 --- a/dio/lib/src/interceptor.dart +++ b/dio/lib/src/interceptor.dart @@ -229,19 +229,19 @@ class Interceptor { } /// The signature of [Interceptor.onRequest]. -typedef InterceptorSendCallback = FutureOr Function( +typedef InterceptorSendCallback = void Function( RequestOptions options, RequestInterceptorHandler handler, ); /// The signature of [Interceptor.onResponse]. -typedef InterceptorSuccessCallback = FutureOr Function( +typedef InterceptorSuccessCallback = void Function( Response response, ResponseInterceptorHandler handler, ); /// The signature of [Interceptor.onError]. -typedef InterceptorErrorCallback = FutureOr Function( +typedef InterceptorErrorCallback = void Function( DioException error, ErrorInterceptorHandler handler, );