Skip to content

Commit

Permalink
chore: Better error message when join room failed
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Nov 19, 2024
1 parent 325431c commit 5fc75ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2812,5 +2812,6 @@
"strikeThrough": "Strikethrough",
"pleaseFillOut": "Please fill out",
"invalidUrl": "Invalid url",
"addLink": "Add link"
"addLink": "Add link",
"unableToJoinChat": "Unable to join chat. Maybe the other party has already closed the conversation."
}
6 changes: 6 additions & 0 deletions lib/utils/localized_exception_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ extension LocalizedExceptionExtension on Object {
}
if (this is String) return toString();
if (this is UiaException) return toString();

if (exceptionContext == ExceptionContext.joinRoom) {
return L10n.of(context).unableToJoinChat;
}

Logs().w('Something went wrong: ', this);
return L10n.of(context).oopsSomethingWentWrong;
}
Expand All @@ -110,4 +115,5 @@ enum ExceptionContext {
changePassword,
checkHomeserver,
checkServerSupportInfo,
joinRoom,
}
11 changes: 5 additions & 6 deletions lib/widgets/future_loading_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Future<Result<T>> showFutureLoadingDialog<T>({
required Future<T> Function() future,
String? title,
String? backLabel,
String Function(dynamic exception)? onError,
bool barrierDismissible = false,
bool delay = true,
ExceptionContext? exceptionContext,
}) async {
final futureExec = future();
final resultFuture = ResultFuture(futureExec);
Expand All @@ -44,7 +44,7 @@ Future<Result<T>> showFutureLoadingDialog<T>({
future: futureExec,
title: title,
backLabel: backLabel,
onError: onError,
exceptionContext: exceptionContext,
),
);
return result ??
Expand All @@ -58,14 +58,14 @@ class LoadingDialog<T> extends StatefulWidget {
final String? title;
final String? backLabel;
final Future<T> future;
final String Function(dynamic exception)? onError;
final ExceptionContext? exceptionContext;

const LoadingDialog({
super.key,
required this.future,
this.title,
this.onError,
this.backLabel,
this.exceptionContext,
});
@override
LoadingDialogState<T> createState() => LoadingDialogState<T>();
Expand All @@ -91,8 +91,7 @@ class LoadingDialogState<T> extends State<LoadingDialog> {
Widget build(BuildContext context) {
final exception = this.exception;
final titleLabel = exception != null
? widget.onError?.call(exception) ??
exception.toLocalizedString(context)
? exception.toLocalizedString(context, widget.exceptionContext)
: widget.title ?? L10n.of(context).loadingPleaseWait;

return AlertDialog.adaptive(
Expand Down

0 comments on commit 5fc75ac

Please sign in to comment.