diff --git a/lib/bean/card/bangumi_history_card.dart b/lib/bean/card/bangumi_history_card.dart index f9bb37bb..1c313062 100644 --- a/lib/bean/card/bangumi_history_card.dart +++ b/lib/bean/card/bangumi_history_card.dart @@ -80,6 +80,7 @@ class _BangumiHistoryCardVState extends State { } catch (e) { KazumiLogger().log(Level.warning, e.toString()); KazumiDialog.dismiss(); + KazumiDialog.showToast(message: '网络资源获取失败 ${e.toString()}'); } }, child: Padding( diff --git a/lib/bean/dialog/dialog_helper.dart b/lib/bean/dialog/dialog_helper.dart index d7786f13..acbb8a6d 100644 --- a/lib/bean/dialog/dialog_helper.dart +++ b/lib/bean/dialog/dialog_helper.dart @@ -42,18 +42,20 @@ class KazumiDialog { }) { final scaffoldContext = context ?? _observer.currentContext; if (scaffoldContext != null) { - ScaffoldMessenger.of(scaffoldContext).showSnackBar( - SnackBar( - content: Text(message), - duration: duration, - action: showUndoButton - ? SnackBarAction( - label: 'Dismiss', - onPressed: () {}, - ) - : null, - ), - ); + ScaffoldMessenger.of(scaffoldContext) + ..removeCurrentSnackBar() + ..showSnackBar( + SnackBar( + content: Text(message), + duration: duration, + action: showUndoButton + ? SnackBarAction( + label: 'Dismiss', + onPressed: () {}, + ) + : null, + ), + ); } else { debugPrint( 'Kazumi Dialog Error: No Scaffold context available to show Toast'); diff --git a/lib/plugins/plugins.dart b/lib/plugins/plugins.dart index 0ea29e23..3bb5ed90 100644 --- a/lib/plugins/plugins.dart +++ b/lib/plugins/plugins.dart @@ -115,7 +115,8 @@ class Plugin { return data; } - Future queryBangumi(String keyword, {bool shouldRethrow = false}) async { + Future queryBangumi(String keyword, + {bool shouldRethrow = false}) async { String queryURL = searchURL.replaceAll('@keyword', keyword); dynamic resp; List searchItems = []; @@ -133,6 +134,7 @@ class Plugin { }; resp = await Request().post(postUri.toString(), options: Options(headers: httpHeaders), + extra: {'customError': '规则检索错误: $name 响应不符合预期'}, data: queryParams, shouldRethrow: shouldRethrow); } else { @@ -140,7 +142,9 @@ class Plugin { 'referer': '$baseUrl/', }; resp = await Request().get(queryURL, - options: Options(headers: httpHeaders), shouldRethrow: shouldRethrow); + options: Options(headers: httpHeaders), + shouldRethrow: shouldRethrow, + extra: {'customError': '规则检索错误: $name 响应不符合预期'}); } var htmlString = resp.data.toString(); @@ -194,7 +198,10 @@ class Plugin { chapterNameList.add(itemName.replaceAll(RegExp(r'\s+'), '')); }); if (chapterUrlList.isNotEmpty && chapterNameList.isNotEmpty) { - Road road = Road(name: '播放列表$count', data: chapterUrlList, identifier: chapterNameList); + Road road = Road( + name: '播放列表$count', + data: chapterUrlList, + identifier: chapterNameList); roadList.add(road); count++; } diff --git a/lib/request/interceptor.dart b/lib/request/interceptor.dart index d3a44fbb..466d2b6f 100644 --- a/lib/request/interceptor.dart +++ b/lib/request/interceptor.dart @@ -29,12 +29,17 @@ class ApiInterceptor extends Interceptor { void onError(DioException err, ErrorInterceptorHandler handler) async { String url = err.requestOptions.uri.toString(); if (!url.contains('heartBeat')) { - KazumiDialog.showToast( - message: await dioError(err), - ); + if (err.requestOptions.extra['customError'] == null) { + KazumiDialog.showToast( + message: await dioError(err), + ); + } else { + KazumiDialog.showToast( + message: err.requestOptions.extra['customError'], + ); + } } super.onError(err, handler); - // super.onError(err, handler); } static Future dioError(DioException error) async { diff --git a/lib/request/request.dart b/lib/request/request.dart index 91a45f83..576468c4 100644 --- a/lib/request/request.dart +++ b/lib/request/request.dart @@ -109,9 +109,11 @@ class Request { if (extra['ua'] != null) { options.headers = {'user-agent': headerUa(type: extra['ua'])}; } + if (extra['customError'] != null) { + options.extra = {'customError': extra['customError']}; + } } options.responseType = resType; - try { response = await dio.get( url,