opt: handle grpc error

This commit is contained in:
bggRGjQaUbCoE
2024-10-14 10:20:52 +08:00
parent e4ae8961e4
commit 6a99dbfe95
3 changed files with 34 additions and 32 deletions

View File

@@ -12,39 +12,36 @@ class HttpError extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SliverToBoxAdapter( return SliverToBoxAdapter(
child: SizedBox( child: Column(
height: 400, crossAxisAlignment: CrossAxisAlignment.center,
child: Column( mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, children: [
mainAxisAlignment: MainAxisAlignment.center, SvgPicture.asset(
children: [ "assets/images/error.svg",
SvgPicture.asset( height: 200,
"assets/images/error.svg", ),
height: 200, const SizedBox(height: 30),
Text(
errMsg ?? '请求异常',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleSmall,
),
const SizedBox(height: 20),
FilledButton.tonal(
onPressed: () {
fn!();
},
style: ButtonStyle(
backgroundColor: WidgetStateProperty.resolveWith((states) {
return Theme.of(context).colorScheme.primary.withAlpha(20);
}),
), ),
const SizedBox(height: 30), child: Text(
Text( btnText ?? '点击重试',
errMsg ?? '请求异常', style: TextStyle(color: Theme.of(context).colorScheme.primary),
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleSmall,
), ),
const SizedBox(height: 20), ),
FilledButton.tonal( ],
onPressed: () {
fn!();
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith((states) {
return Theme.of(context).colorScheme.primary.withAlpha(20);
}),
),
child: Text(
btnText ?? '点击重试',
style: TextStyle(color: Theme.of(context).colorScheme.primary),
),
),
],
),
), ),
); );
} }

View File

@@ -102,6 +102,11 @@ class GrpcRepo {
try { try {
return await request(); return await request();
} catch (e) { } catch (e) {
if (e is GrpcError) {
if (e.message == '12061') {
return {'status': false, 'msg': 'UP主已关闭评论区'}; // to be comfirm
}
}
return {'status': false, 'msg': e.toString()}; return {'status': false, 'msg': e.toString()};
} }
} }

View File

@@ -74,7 +74,7 @@ class VideoReplyReplyController extends CommonController
@override @override
Future queryData([bool isRefresh = true]) { Future queryData([bool isRefresh = true]) {
if (noMore.value == '没有更多了') return Future.value(); if (['没有更多了', '还没有评论'].contains(noMore.value)) return Future.value();
return super.queryData(isRefresh); return super.queryData(isRefresh);
} }