localizedErrorMessage function
- AppLocalizations l10n,
- Object error, {
- String? logName,
- bool saving = false,
userFriendlyMessage for a screen that has an AppLocalizations: the errors with localized copy get it, everything else falls through to the English mapper (which also logs the original error).
Today those are the database's errors. A refusal (isAccessDenied) reads
"You don't have access to this." in the learner's language, not an
invitation to retry, except an invitation or a share refused by the other
person's privacy switch (isInviteeInvitationsOff,
isRecipientSharingOff), which says so instead. Any other one says the
data did not load or, with saving, that the change was not saved.
Implementation
String localizedErrorMessage(
AppLocalizations l10n,
Object error, {
String? logName,
bool saving = false,
}) {
// Logged like every other error, localized or not.
final english = userFriendlyMessage(error, logName: logName, saving: saving);
if (isInviteeInvitationsOff(error)) return l10n.errorInviteeInvitationsOff;
if (isRecipientSharingOff(error)) return l10n.errorRecipientSharingOff;
if (isAccessDenied(error)) return l10n.errorNoAccess;
if (error is PostgrestException) {
return saving ? l10n.errorSaveFailed : l10n.errorLoadFailed;
}
return english;
}