Skip to content

Commit d71feff

Browse files
committed
Optimise error message
1 parent 3b50395 commit d71feff

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

example/lib/home.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,29 @@ class HomeState extends State<Home> with SingleTickerProviderStateMixin {
391391
),
392392
);
393393
}
394+
} on RecipientNotReadyException catch (e) {
395+
debugPrint('Recipient not ready: $e');
396+
if (context.mounted) {
397+
showDialog(
398+
context: context,
399+
builder: (ctx) => AlertDialog(
400+
title: const Text('Recipient Not Ready'),
401+
content: Text(
402+
'Could not send notification to $recipient.\n\n'
403+
'The recipient may need to log in and update '
404+
'their app setup in their Pod before you can '
405+
'send notifications to them.\n\n'
406+
'Details: $e',
407+
),
408+
actions: [
409+
ElevatedButton(
410+
onPressed: () => Navigator.pop(ctx),
411+
child: const Text('OK'),
412+
),
413+
],
414+
),
415+
);
416+
}
394417
} on Exception catch (e) {
395418
debugPrint('Failed to send notification: $e');
396419
if (context.mounted) {

lib/src/widgets/grant_permission_form.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ class _GrantPermissionFormState extends State<GrantPermissionForm> {
404404

405405
final permissions = selectedPermList.join(', ');
406406

407+
final notificationFailures = <String>[];
408+
407409
for (final recipientWebId in finalWebIdList) {
408410
try {
409411
await sendNotification(
@@ -418,13 +420,32 @@ class _GrantPermissionFormState extends State<GrantPermissionForm> {
418420
}),
419421
priority: 1,
420422
);
423+
} on RecipientNotReadyException catch (e) {
424+
debugPrint(
425+
'[GrantPermissionForm] '
426+
'Recipient not ready for $recipientWebId: $e',
427+
);
428+
notificationFailures.add(
429+
recipientWebId as String,
430+
);
421431
} on Object catch (e) {
422432
debugPrint(
423433
'[GrantPermissionForm] '
424434
'Failed to send notification to $recipientWebId: $e',
425435
);
426436
}
427437
}
438+
439+
if (notificationFailures.isNotEmpty) {
440+
final names = notificationFailures.join(', ');
441+
_showSnackBar(
442+
'Permission granted, but could not notify: $names. '
443+
'The recipient(s) may need to log in and update '
444+
'their app setup in their Pod first.',
445+
ActionColors.warning,
446+
duration: const Duration(seconds: 8),
447+
);
448+
}
428449
}
429450

430451
// Update permissions table

0 commit comments

Comments
 (0)