Commit 8de2f9cb by tanghuan

网络请求异常捕获处理

1 parent bd25deab
......@@ -98,6 +98,10 @@ class LoginPhoneCubit extends Cubit<LoginPhoneState> {
// 发送验证码
var result = await _phoneAuthRepository.verifyCode(phone, 1);
if (result == null) {
Fluttertoast.showToast(msg: '发送请求失败', gravity: ToastGravity.TOP, backgroundColor: Colors.red);
return;
}
if (result['code'] != 0) {
Fluttertoast.showToast(msg: result['error'], gravity: ToastGravity.TOP, backgroundColor: Colors.red);
return;
......
import 'dart:io';
import 'package:appframe/config/locator.dart';
import 'package:appframe/services/api_service.dart';
import 'package:dio/dio.dart';
......@@ -22,13 +24,17 @@ class PhoneAuthRepository {
/// }
///
Future<dynamic> bindCheck(String userid) async {
Response resp = await _appService.get(
'/api/v1/comm/phone/bind/check',
queryParameters: {
"userid": userid,
},
);
return resp.data;
try {
Response resp = await _appService.get(
'/api/v1/comm/phone/bind/check',
queryParameters: {
"userid": userid,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -38,15 +44,19 @@ class PhoneAuthRepository {
/// }
///
Future<dynamic> bind(String userid, String phone, String verifyCode) async {
Response resp = await _appService.post(
'/api/v1/comm/phone/bind',
{
"userid": userid,
"phone": phone,
"verifyCode": verifyCode,
},
);
return resp.data;
try {
Response resp = await _appService.post(
'/api/v1/comm/phone/bind',
{
"userid": userid,
"phone": phone,
"verifyCode": verifyCode,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -59,14 +69,18 @@ class PhoneAuthRepository {
/// type=0 验证码登陆下发
///
Future<dynamic> verifyCode(String phone, int type) async {
Response resp = await _appService.get(
'/api/v1/comm/phone/verifycode',
queryParameters: {
"phone": phone,
"type": type,
},
);
return resp.data;
try {
Response resp = await _appService.get(
'/api/v1/comm/phone/verifycode',
queryParameters: {
"phone": phone,
"type": type,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -77,14 +91,18 @@ class PhoneAuthRepository {
/// }
///
Future<dynamic> login(String phone, String verifyCode) async {
Response resp = await _appService.post(
'/api/v1/comm/phone/loginv2',
{
"phone": phone,
"verifyCode": verifyCode,
},
);
return resp.statusCode == 200 ? resp.data : null;
try {
Response resp = await _appService.post(
'/api/v1/comm/phone/loginv2',
{
"phone": phone,
"verifyCode": verifyCode,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -94,22 +112,30 @@ class PhoneAuthRepository {
/// }
///
Future<dynamic> unbind(String userid) async {
Response resp = await _appService.post(
'/api/v1/comm/phone/unbind',
{
"userid": userid,
},
);
return resp.data;
try {
Response resp = await _appService.post(
'/api/v1/comm/phone/unbind',
{
"userid": userid,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
Future<dynamic> unbindPhone(String phone) async {
Response resp = await _appService.post(
'/api/v1/comm/phone/unbind',
{
"phone": phone,
},
);
return resp.data;
try {
Response resp = await _appService.post(
'/api/v1/comm/phone/unbind',
{
"phone": phone,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
}
import 'dart:io';
import 'package:appframe/config/locator.dart';
import 'package:appframe/services/api_service.dart';
import 'package:dio/dio.dart';
......@@ -10,14 +12,18 @@ class SubsRepository {
}
Future<dynamic> userGroups(String type, String userid, String classCode) async {
Response resp = await _appService.post(
'/api/v1/comm/subs/usergroups',
{
"type": type,
"userid": userid,
"classCode": classCode,
},
);
return resp.data;
try {
Response resp = await _appService.post(
'/api/v1/comm/subs/usergroups',
{
"type": type,
"userid": userid,
"classCode": classCode,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
}
......@@ -18,28 +18,36 @@ class UserAuthRepository {
/// }
///
Future<dynamic> updateUser(String userid, String name, String nickName, String avatar) async {
Response resp = await _appService.post(
'/api/v1/comm/user/update',
{
"userid": userid,
"name": name,
"nickName": nickName,
"avatar": avatar,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
try {
Response resp = await _appService.post(
'/api/v1/comm/user/update',
{
"userid": userid,
"name": name,
"nickName": nickName,
"avatar": avatar,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
Future<dynamic> appleLogin(String userid, String authorizationCode, String identityToken) async {
Response resp = await _appService.post(
'/api/v1/comm/user/applelogin',
{
"user": userid,
"authorizationCode": authorizationCode,
"identityToken": identityToken,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
try {
Response resp = await _appService.post(
'/api/v1/comm/user/applelogin',
{
"user": userid,
"authorizationCode": authorizationCode,
"identityToken": identityToken,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -49,14 +57,18 @@ class UserAuthRepository {
/// "error": "",
/// }
Future<dynamic> exchangeId(String userid) async {
Response resp = await _appService.post(
'/api/v1/comm/user/exchangeid',
{
"userId": userid,
"type": "apple",
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
try {
Response resp = await _appService.post(
'/api/v1/comm/user/exchangeid',
{
"userId": userid,
"type": "apple",
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
......@@ -65,14 +77,18 @@ class UserAuthRepository {
/// "code": 0,
/// }
Future<dynamic> newBinding(String userid, String bxeUserId, String type) async {
Response resp = await _appService.post(
'/api/v1/comm/user/newbinding',
{
"userId": userid,
"bxeUserId": bxeUserId,
"type": type,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
try {
Response resp = await _appService.post(
'/api/v1/comm/user/newbinding',
{
"userId": userid,
"bxeUserId": bxeUserId,
"type": type,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
}
......@@ -13,30 +13,40 @@ class WechatAuthRepository {
}
Future<dynamic> codeToSk(String code) async {
Response resp = await _apiService.post(
'/login/applet/wkbxe/codeToSkByApp?version=1.0.0',
{
"appCode": "bxeapp",
"params": {"code": code},
},
);
debugPrint('登录结果: $resp');
return resp.statusCode == HttpStatus.ok ? resp.data : null;
try {
Response resp = await _apiService.post(
'/login/applet/wkbxe/codeToSkByApp?version=1.0.0',
{
"appCode": "bxeapp",
"params": {"code": code},
},
);
debugPrint('登录结果: $resp');
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException catch (e) {
debugPrint('codeToSk网络异常: $e');
return null;
}
}
Future<dynamic> getTicket() async {
Response resp = await _apiService.post(
'/login/applet/wkbxe/getTicketByApp?version=1.0.0',
{
"appCode": "bxeapp",
"params": {},
},
);
debugPrint('获取ticket: $resp');
return resp.statusCode == HttpStatus.ok ? resp.data : null;
try {
Response resp = await _apiService.post(
'/login/applet/wkbxe/getTicketByApp?version=1.0.0',
{
"appCode": "bxeapp",
"params": {},
},
);
debugPrint('获取ticket: $resp');
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException catch (e) {
debugPrint('getTicket网络异常: $e');
return null;
}
}
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!