mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-17 05:43:41 +00:00
fix: dio timeout don't throw exception (#133)
This commit is contained in:
1 parent
32061200a5
commit
c3b28c7034
3 files changed
+12
-5
No files matched your search
@@ -34,6 +34,7 @@ class _Client {
|
|||||||
}
|
}
|
||||||
dio.options.baseUrl = baseUrl;
|
dio.options.baseUrl = baseUrl;
|
||||||
dio.options.contentType = Headers.jsonContentType;
|
dio.options.contentType = Headers.jsonContentType;
|
||||||
|
dio.options.sendTimeout = const Duration(seconds: 5);
|
||||||
dio.options.connectTimeout = const Duration(seconds: 5);
|
dio.options.connectTimeout = const Duration(seconds: 5);
|
||||||
dio.options.receiveTimeout = const Duration(seconds: 60);
|
dio.options.receiveTimeout = const Duration(seconds: 60);
|
||||||
dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) {
|
dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) {
|
||||||
@@ -46,7 +47,8 @@ class _Client {
|
|||||||
_instance!.dio = dio;
|
_instance!.dio = dio;
|
||||||
if (isUnixSocket) {
|
if (isUnixSocket) {
|
||||||
(_instance!.dio.httpClientAdapter as IOHttpClientAdapter)
|
(_instance!.dio.httpClientAdapter as IOHttpClientAdapter)
|
||||||
.onHttpClientCreate = (client) {
|
.createHttpClient = () {
|
||||||
|
final client = HttpClient();
|
||||||
client.connectionFactory =
|
client.connectionFactory =
|
||||||
(Uri uri, String? proxyHost, int? proxyPort) {
|
(Uri uri, String? proxyHost, int? proxyPort) {
|
||||||
return Socket.startConnect(
|
return Socket.startConnect(
|
||||||
@@ -79,7 +81,12 @@ Future<T> _parse<T>(
|
|||||||
} else {
|
} else {
|
||||||
throw Exception(result);
|
throw Exception(result);
|
||||||
}
|
}
|
||||||
} on DioError catch (e) {
|
} on DioException catch (e) {
|
||||||
|
if (e.type == DioExceptionType.sendTimeout ||
|
||||||
|
e.type == DioExceptionType.receiveTimeout ||
|
||||||
|
e.type == DioExceptionType.connectionTimeout) {
|
||||||
|
throw Exception(Result(code: 1000, msg: "request timeout"));
|
||||||
|
}
|
||||||
throw Exception(Result(code: 1000, msg: e.message));
|
throw Exception(Result(code: 1000, msg: e.message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,10 +237,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: dio
|
name: dio
|
||||||
sha256: "0894a098594263fe1caaba3520e3016d8a855caeb010a882273189cca10f11e9"
|
sha256: a9d76e72985d7087eb7c5e7903224ae52b337131518d127c554b9405936752b8
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.1.1"
|
version: "5.2.1+1"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ dependencies:
|
|||||||
styled_widget: ^0.4.0+3
|
styled_widget: ^0.4.0+3
|
||||||
context_menus: ^1.0.2
|
context_menus: ^1.0.2
|
||||||
json_annotation: ^4.6.0
|
json_annotation: ^4.6.0
|
||||||
dio: ^5.1.1
|
dio: ^5.2.1
|
||||||
path_provider: ^2.0.11
|
path_provider: ^2.0.11
|
||||||
file_picker: ^5.2.5
|
file_picker: ^5.2.5
|
||||||
macos_secure_bookmarks: ^0.2.1
|
macos_secure_bookmarks: ^0.2.1
|
||||||
|
|||||||
Reference in new issue
Block a user