Skip to content

Commit

Permalink
update dio 5
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Aug 14, 2023
1 parent e087c3d commit 7dc992b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions lib/common/net/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ class HttpManager {
option.headers = headers;
}

resultError(DioError e) {
resultError(DioException e) {
Response? errorResponse;
if (e.response != null) {
errorResponse = e.response;
} else {
errorResponse = new Response(statusCode: 666, requestOptions: RequestOptions(path: url));
}
if (e.type == DioErrorType.connectTimeout ||
e.type == DioErrorType.receiveTimeout) {
if (e.type == DioExceptionType.connectionTimeout ||
e.type == DioExceptionType.sendTimeout ||
e.type == DioExceptionType.receiveTimeout) {
errorResponse!.statusCode = Code.NETWORK_TIMEOUT;
}
return new ResultData(
Expand All @@ -72,10 +73,10 @@ class HttpManager {
Response response;
try {
response = await _dio.request(url, data: params, options: option);
} on DioError catch (e) {
} on DioException catch (e) {
return resultError(e);
}
if (response.data is DioError) {
if (response.data is DioException) {
return resultError(response.data);
}
return response.data;
Expand Down
4 changes: 2 additions & 2 deletions lib/common/net/interceptors/error_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class ErrorInterceptors extends InterceptorsWrapper {
//没有网络
var connectivityResult = await (new Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.none) {
return handler.reject(DioError(
return handler.reject(DioException(
requestOptions: options,
type: DioErrorType.other,
type: DioExceptionType.unknown,
response: Response(
requestOptions: options,
data: new ResultData(
Expand Down
4 changes: 2 additions & 2 deletions lib/common/net/interceptors/header_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class HeaderInterceptors extends InterceptorsWrapper {
@override
onRequest(RequestOptions options, handler) async {
///超时
options.connectTimeout = 30000;
options.receiveTimeout = 30000;
options.connectTimeout = Duration(seconds: 30);
options.receiveTimeout = Duration(seconds: 30);

return super.onRequest(options, handler);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/common/net/interceptors/log_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class LogsInterceptors extends InterceptorsWrapper {
}

@override
onError(DioError err, handler) async {
onError(DioException err, handler) async {
if (Config.DEBUG!) {
print('请求异常: ' + err.toString());
print('请求异常信息: ' + (err.response?.toString() ?? ""));
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ packages:
dependency: "direct main"
description:
name: dio
sha256: "5fd6e152bdbc876bc6e81910e16a2bd36e0c68e23d87316e8da67a1ec8fd7b1c"
sha256: "9d6445da1caf8412070670c03c39ad5b12a78cc8c2361417b220905a2bcbdd2f"
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.4"
version: "5.3.1"
ffi:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
pub_semver: 2.1.4
flutter_svg: 1.0.0
flutter_slidable: ^0.6.0-nullsafety.0
dio: 4.0.4
dio: 5.3.1
#fconsole: 2.2.1
path_provider: 2.0.10
webview_flutter: 3.0.0
Expand Down

0 comments on commit 7dc992b

Please sign in to comment.