mod: 代码整理

This commit is contained in:
guozhigq
2023-07-25 23:44:09 +08:00
parent 6d9f66c420
commit 7745ea076b
74 changed files with 387 additions and 424 deletions

View File

@ -151,7 +151,7 @@ class Request {
cancelToken: cancelToken,
);
return response;
} on DioError catch (e) {
} on DioException catch (e) {
print('get error: $e');
return Future.error(await ApiInterceptor.dioError(e));
}
@ -173,7 +173,7 @@ class Request {
);
print('post success: ${response.data}');
return response;
} on DioError catch (e) {
} on DioException catch (e) {
print('post error: $e');
return Future.error(await ApiInterceptor.dioError(e));
}
@ -193,7 +193,7 @@ class Request {
print('downloadFile success: ${response.data}');
return response.data;
} on DioError catch (e) {
} on DioException catch (e) {
print('downloadFile error: $e');
return Future.error(ApiInterceptor.dioError(e));
}

View File

@ -1,12 +1,12 @@
import 'package:dio/dio.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart' hide Response;
// import 'package:get/get.dart' hide Response;
class ApiInterceptor extends Interceptor {
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
print("请求之前");
// print("请求之前");
// 在请求之前添加头部或认证信息
// options.headers['Authorization'] = 'Bearer token';
// options.headers['Content-Type'] = 'application/json';
@ -19,30 +19,30 @@ class ApiInterceptor extends Interceptor {
}
@override
void onError(DioError err, ErrorInterceptorHandler handler) async {
void onError(DioException err, ErrorInterceptorHandler handler) async {
// 处理网络请求错误
// handler.next(err);
SmartDialog.showToast(await dioError(err));
super.onError(err, handler);
}
static Future dioError(DioError error) async {
static Future dioError(DioException error) async {
switch (error.type) {
case DioErrorType.badCertificate:
case DioExceptionType.badCertificate:
return '证书有误!';
case DioErrorType.badResponse:
case DioExceptionType.badResponse:
return '服务器异常,请稍后重试!';
case DioErrorType.cancel:
case DioExceptionType.cancel:
return "请求已被取消,请重新请求";
case DioErrorType.connectionError:
case DioExceptionType.connectionError:
return '连接错误,请检查网络设置';
case DioErrorType.connectionTimeout:
case DioExceptionType.connectionTimeout:
return "网络连接超时,请检查网络设置";
case DioErrorType.receiveTimeout:
case DioExceptionType.receiveTimeout:
return "响应超时,请稍后重试!";
case DioErrorType.sendTimeout:
case DioExceptionType.sendTimeout:
return "发送请求超时,请检查网络设置";
case DioErrorType.unknown:
case DioExceptionType.unknown:
var res = await checkConect();
return res + " \n 网络异常,请稍后重试!";
default:

View File

@ -1,5 +1,3 @@
import 'dart:developer';
import 'package:pilipala/http/index.dart';
import 'package:pilipala/models/bangumi/info.dart';
import 'package:pilipala/models/common/search_type.dart';
@ -57,7 +55,7 @@ class SearchHttp {
'page': page
});
if (res.data['code'] == 0 && res.data['data']['numPages'] > 0) {
var data;
Object data;
switch (searchType) {
case SearchType.video:
data = SearchVideoModel.fromJson(res.data['data']);

View File

@ -1,5 +1,3 @@
import 'dart:developer';
import 'package:pilipala/http/api.dart';
import 'package:pilipala/http/init.dart';
import 'package:pilipala/models/model_hot_video_item.dart';

View File

@ -125,7 +125,6 @@ class VideoHttp {
return {'status': false, 'data': []};
}
} catch (err) {
print('🐯:$err');
return {'status': false, 'data': [], 'msg': err};
}
}
@ -338,7 +337,7 @@ class VideoHttp {
// 视频播放进度
static Future heartBeat({bvid, cid, progress, realtime}) async {
var res = await Request().post(Api.heartBeat, queryParameters: {
await Request().post(Api.heartBeat, queryParameters: {
// 'aid': aid,
'bvid': bvid,
'cid': cid,