@@ -1429,12 +1429,25 @@ class _SavedSnippetComposeBoxBody extends _ComposeBoxBody {
1429
1429
return Align (
1430
1430
alignment: Alignment .centerRight,
1431
1431
child: IconButton (
1432
- onPressed: () {
1433
- Navigator .pop (context);
1434
- // TODO handle validation errors; server errors
1435
- createSavedSnippet (store.connection,
1436
- title: controller.title.textNormalized,
1437
- content: controller.content.textNormalized);
1432
+ onPressed: () async {
1433
+ // TODO client-side validations
1434
+ try {
1435
+ await createSavedSnippet (store.connection,
1436
+ title: controller.title.textNormalized,
1437
+ content: controller.content.textNormalized);
1438
+ if (! context.mounted) return ;
1439
+ Navigator .pop (context);
1440
+ } on ApiRequestException catch (e) {
1441
+ if (! context.mounted) return ;
1442
+ final zulipLocalizations = ZulipLocalizations .of (context);
1443
+ final message = switch (e) {
1444
+ ZulipApiException () => zulipLocalizations.errorServerMessage (e.message),
1445
+ _ => e.message,
1446
+ };
1447
+ showErrorDialog (context: context,
1448
+ title: zulipLocalizations.errorFailedToCreateSavedSnippet,
1449
+ message: message);
1450
+ }
1438
1451
}, icon: Icon (ZulipIcons .check, color: designVariables.icon)));
1439
1452
}
1440
1453
}
0 commit comments