diff --git a/lib/src/api_options/api_options.dart b/lib/src/api_options/api_options.dart index e1fd499..920bf23 100644 --- a/lib/src/api_options/api_options.dart +++ b/lib/src/api_options/api_options.dart @@ -5,13 +5,13 @@ class ApiOptions { this.headers = const {}, this.receiveTimeout, this.sendTimeout, + this.connectTimeout, this.refreshCache, this.cacheResponse, this.expireDuration, this.cancelToken, this.ignoreAutoRefresh = true, this.responseType, - }); ResponseType? responseType; @@ -21,6 +21,8 @@ class ApiOptions { Duration? sendTimeout; + Duration? connectTimeout; + bool? refreshCache; bool? cacheResponse; diff --git a/lib/src/api_service_impl.dart b/lib/src/api_service_impl.dart index 92977c4..3512779 100644 --- a/lib/src/api_service_impl.dart +++ b/lib/src/api_service_impl.dart @@ -13,8 +13,10 @@ class ApiServiceImpl implements ApiService { ApiServiceImpl({required this.baseUrl, this.interceptors, this.apiOptions}) { _dio = Dio() ..options.contentType = Headers.jsonContentType - ..options.connectTimeout = Duration(minutes: 1) - ..options.receiveTimeout = Duration(minutes: 1, seconds: 30); + ..options.connectTimeout = + apiOptions?.connectTimeout ?? Duration(minutes: 1) + ..options.receiveTimeout = + apiOptions?.receiveTimeout ?? Duration(minutes: 1, seconds: 30); if (interceptors != null && interceptors!.isNotEmpty) { _dio!.interceptors.addAll(interceptors!); diff --git a/lib/src/interceptors/error_interceptor.dart b/lib/src/interceptors/error_interceptor.dart index a80552f..c9558fc 100644 --- a/lib/src/interceptors/error_interceptor.dart +++ b/lib/src/interceptors/error_interceptor.dart @@ -106,6 +106,15 @@ abstract class ErrorInterceptor extends Interceptor { error: error.error, ), ); + } else if (error.type == DioExceptionType.connectionError) { + return handler.reject( + NoInternetError( + requestOptions: error.requestOptions, + response: error.response, + type: error.type, + error: error.error, + ), + ); } if (error.type == DioExceptionType.cancel) {