Skip to content

Commit

Permalink
接口异常处理修复
Browse files Browse the repository at this point in the history
  • Loading branch information
simplezhli committed Jul 17, 2019
1 parent 1082992 commit 2f86e7a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/login/register_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class _RegisterState extends State<Register> {
controller: _nameController,
maxLength: 11,
keyboardType: TextInputType.phone,
hintText: "请输入账号",
hintText: "请输入手机号",
),
Gaps.vGap10,
MyTextField(
controller: _vCodeController,
keyboardType: TextInputType.number,
getVCode: (){

Toast.show("并没有真正发送哦,直接登录吧!");
},
maxLength: 6,
hintText: "请输入验证码",
Expand Down
2 changes: 1 addition & 1 deletion lib/login/sms_login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _SMSLoginState extends State<SMSLogin> {
controller: _phoneController,
maxLength: 11,
keyboardType: TextInputType.phone,
hintText: "请输入账号",
hintText: "请输入手机号",
),
Gaps.vGap10,
MyTextField(
Expand Down
14 changes: 7 additions & 7 deletions lib/mvp/base_page_presenter.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import 'package:dio/dio.dart';
import 'package:flutter_deer/net/dio_utils.dart';
import 'package:flutter_deer/net/error_handle.dart';
import 'package:flutter_deer/net/net.dart';
import 'package:meta/meta.dart';

import 'mvps.dart';
Expand Down Expand Up @@ -51,7 +50,7 @@ class BasePagePresenter<V extends IMvpView> extends IPresenter {
}
},
onError: (code, msg){
_onError(code, msg, isClose, onError);
_onError(code, msg, onError);
}
);
}
Expand All @@ -71,7 +70,7 @@ class BasePagePresenter<V extends IMvpView> extends IPresenter {
}
},
onError: (code, msg){
_onError(code, msg, isClose, onError);
_onError(code, msg, onError);
}
);
}
Expand All @@ -98,13 +97,14 @@ class BasePagePresenter<V extends IMvpView> extends IPresenter {
}
},
onError: (code, msg){
_onError(code, msg, isClose, onError);
_onError(code, msg, onError);
}
);
}

_onError(int code, String msg, bool isClose, Function(int code, String mag) onError){
if (isClose) view.closeProgress();
_onError(int code, String msg, Function(int code, String mag) onError){
/// 异常时直接关闭加载圈,不受isClose影响
view.closeProgress();
if (code != ExceptionHandle.cancel_error){
view.showToast(msg);
}
Expand Down
6 changes: 5 additions & 1 deletion lib/net/dio_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ class DioUtils {
_code = _map["code"];
_msg = _map["message"];
if (_map.containsKey("data")){
_data = EntityFactory.generateOBJ(_map["data"]);
if (T.toString() == "String"){
_data = _map["data"].toString() as T;
}else{
_data = EntityFactory.generateOBJ(_map["data"]);
}
}
}catch(e){
print(e);
Expand Down
2 changes: 1 addition & 1 deletion lib/net/intercept.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class AdapterInterceptor extends Interceptor{
} catch (e) {
Log.d("异常信息:$e");
// 解析异常直接按照返回原数据处理(一般为返回500,503 HTML页面代码)
result = content;
result = sprintf(FAILURE_FORMAT, [response.statusCode, "服务器异常(${response.statusCode})"]);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/net/net.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'error_handle.dart';
export 'dio_utils.dart';
export 'api.dart';
3 changes: 1 addition & 2 deletions lib/order/presenter/order_search_presenter.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import 'package:flutter_deer/mvp/base_page_presenter.dart';
import 'package:flutter_deer/net/api.dart';
import 'package:flutter_deer/net/dio_utils.dart';
import 'package:flutter_deer/net/net.dart';
import 'package:flutter_deer/order/models/search_entity.dart';
import 'package:flutter_deer/widgets/state_layout.dart';

Expand Down

0 comments on commit 2f86e7a

Please sign in to comment.