Skip to content

Commit c568247

Browse files
committed
修改http,增加拦截器
1 parent bd02f50 commit c568247

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/common/net/interceptors/error_interceptor.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const NOT_TIP_KEY = "noTip";
1212
* on 2019/3/23.
1313
*/
1414
class ErrorInterceptors extends InterceptorsWrapper {
15-
1615
final Dio _dio;
1716

1817
ErrorInterceptors(this._dio);
@@ -21,16 +20,18 @@ class ErrorInterceptors extends InterceptorsWrapper {
2120
onRequest(RequestOptions options) async {
2221
//没有网络
2322
var connectivityResult = await (new Connectivity().checkConnectivity());
23+
var noTip = options.headers[NOT_TIP_KEY];
2424
if (connectivityResult == ConnectivityResult.none) {
25-
return _dio.reject(DioError(response: Response(statusCode: Code.NETWORK_ERROR)));
25+
return _dio.resolve(new ResultData(Code.errorHandleFunction(Code.NETWORK_ERROR, "", noTip ?? false), false, Code.NETWORK_ERROR));
2626
}
2727
return options;
2828
}
2929

3030
@override
3131
onError(DioError e) {
3232
Response errorResponse;
33-
var noTip = e.request.headers[NOT_TIP_KEY];
33+
print("………………………………");
34+
var noTip = e.response != null ? e.response.headers[NOT_TIP_KEY] : true;
3435
if (e.response != null) {
3536
errorResponse = e.response;
3637
} else {

lib/common/net/interceptors/log_interceptor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class LogsInterceptors extends InterceptorsWrapper {
3333
onError(DioError err) {
3434
if (Config.DEBUG) {
3535
print('请求异常: ' + err.toString());
36-
print('请求异常url: ' + err.request.path);
36+
print('请求异常信息: ' + err.response?.toString() ?? "");
3737
}
3838
return err;
3939
}

0 commit comments

Comments
 (0)