Skip to content

Commit

Permalink
TW-1453: Error handling when update profile fail
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Mar 20, 2024
1 parent e4612a8 commit d7cad62
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:fluffychat/app_state/failure.dart';
import 'package:fluffychat/app_state/success.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/app_state/room/upload_content_state.dart';
import 'package:fluffychat/domain/app_state/settings/update_profile_failure.dart';
import 'package:fluffychat/domain/app_state/settings/update_profile_success.dart';
import 'package:fluffychat/domain/usecase/room/upload_content_for_web_interactor.dart';
import 'package:fluffychat/domain/usecase/room/upload_content_interactor.dart';
Expand Down Expand Up @@ -375,6 +376,19 @@ class SettingsProfileController extends State<SettingsProfile>
Logs().e(
'SettingsProfile::_handleUploadAvatarOnData() - failure: $failure',
);
if (failure is UploadContentFailed) {
TwakeDialog.hideLoadingDialog(context);
TwakeSnackBar.show(
context,
failure.exception.toString(),
);
} else if (failure is FileTooBigMatrix) {
TwakeDialog.hideLoadingDialog(context);
TwakeSnackBar.show(
context,
failure.fileTooBigMatrixException.toString(),
);
}
},
(success) {
Logs().d(
Expand Down Expand Up @@ -437,6 +451,9 @@ class SettingsProfileController extends State<SettingsProfile>
Logs().e(
'SettingsProfile::_handleUploadProfileOnData() - failure: $failure',
);
if (failure is UpdateProfileFailure) {
_handleUpdateProfileFailure(failure.exception.toString());
}
},
(success) {
Logs().d(
Expand All @@ -447,7 +464,8 @@ class SettingsProfileController extends State<SettingsProfile>
final newProfile = Profile(
userId: client.userID!,
displayName: success.displayName ?? displayName,
avatarUrl: success.avatar,
avatarUrl:
success.avatar == null ? currentProfile?.avatarUrl : null,
);
_sendAccountDataEvent(profile: newProfile);
if (!success.isDeleteAvatar) {
Expand Down Expand Up @@ -549,6 +567,18 @@ class SettingsProfileController extends State<SettingsProfile>
});
}

void _handleUpdateProfileFailure(String errorMessage) {
TwakeDialog.hideLoadingDialog(context);
TwakeSnackBar.show(
context,
errorMessage,
);
_clearImageInLocal();
if (currentProfile != null) {
_sendAccountDataEvent(profile: currentProfile!);
}
}

@override
void initState() {
_handleViewState();
Expand Down

0 comments on commit d7cad62

Please sign in to comment.