From 92a34646f6e4f910e8411978788f5bf6b21ab497 Mon Sep 17 00:00:00 2001 From: Vatsal Gandhi Date: Thu, 11 Sep 2025 15:17:39 +0530 Subject: [PATCH 1/2] feat(api-options): add connectTimeout to ApiOptions --- lib/src/api_options/api_options.dart | 4 +++- lib/src/api_service_impl.dart | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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!); From 8803089dc007465fe6c51f9f9b8892ac7dd3ef5a Mon Sep 17 00:00:00 2001 From: Vatsal Gandhi Date: Thu, 11 Sep 2025 15:17:48 +0530 Subject: [PATCH 2/2] fix(error-interceptor): handle connection error in ErrorInterceptor --- lib/src/interceptors/error_interceptor.dart | 9 +++++++++ 1 file changed, 9 insertions(+) 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) {