Commit c53ccd34 authored by “Icebear”'s avatar “Icebear”

优化code,msg,data

parent 6f0c4e5a
...@@ -132,5 +132,5 @@ ResultData resultError(DioError e) { ...@@ -132,5 +132,5 @@ ResultData resultError(DioError e) {
errorResponse.statusCode = Code.NETWORK_TIMEOUT; errorResponse.statusCode = Code.NETWORK_TIMEOUT;
} }
return new ResultData( return new ResultData(
errorResponse.statusMessage, false, errorResponse.statusCode); null, false,-1,errorResponse.statusMessage);
} }
...@@ -9,7 +9,7 @@ class ResponseInterceptors extends InterceptorsWrapper { ...@@ -9,7 +9,7 @@ class ResponseInterceptors extends InterceptorsWrapper {
try { try {
if (option.contentType != null && option.contentType.contains("text")) { if (option.contentType != null && option.contentType.contains("text")) {
response.data = ResultData(response.data, true, 200); response.data = ResultData(response.data, true, 0,'');
handler.next(response); handler.next(response);
} }
...@@ -18,25 +18,23 @@ class ResponseInterceptors extends InterceptorsWrapper { ...@@ -18,25 +18,23 @@ class ResponseInterceptors extends InterceptorsWrapper {
///内层需要根据公司实际返回结构解析,一般会有code,data,msg字段 ///内层需要根据公司实际返回结构解析,一般会有code,data,msg字段
int code = response.data["code"]; int code = response.data["code"];
String msg = response.data["msg"];
if (code == 0) { if (code == 0) {
response.data = ResultData(response.data, true, 200, response.data = ResultData(response.data, true, code ,msg);
headers: response.headers);
handler.next(response); handler.next(response);
} else { } else {
response.data = ResultData(response.data, false, 200, response.data = ResultData(response.data, false, code, msg);
headers: response.headers);
handler.next(response); handler.next(response);
} }
} }
} catch (e) { } catch (e) {
print("ResponseError====" + e.toString() + "****" + option.path); print("ResponseError====" + e.toString() + "****" + option.path);
response.data = ResultData(response.data, false, response.statusCode, response.data = ResultData(response.data, false, -1, '网络有误');
headers: response.headers);
handler.next(response); handler.next(response);
} }
response.data = ResultData(response.data, false, response.statusCode, headers: response.headers); response.data = ResultData(response.data, false, -1,'网络有误');
handler.next(response); handler.next(response);
} }
} }
...@@ -2,7 +2,7 @@ class ResultData { ...@@ -2,7 +2,7 @@ class ResultData {
var data; var data;
bool isSuccess; bool isSuccess;
int code; int code;
var headers; var msg;
ResultData(this.data, this.isSuccess, this.code, {this.headers}); ResultData(this.data, this.isSuccess, this.code, this.msg);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment