Skip to content

Commit

Permalink
feat: display user friendly error in case of 401 error from Stack
Browse files Browse the repository at this point in the history
As the stack does not translate error messages and 401 is the most
common error then we intercept this specific error to translate it on
client side
  • Loading branch information
Ldoppea committed Nov 29, 2021
1 parent 0839241 commit 60520fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/App/Pages/Accounts/LoginPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Bit.App.Abstractions;
using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.Core;
using Bit.Core.Abstractions;
Expand All @@ -9,6 +9,7 @@
using Bit.App.Utilities;
using Xamarin.Forms;
using System.Windows.Input;
using System.Net;

namespace Bit.App.Pages
{
Expand Down Expand Up @@ -203,8 +204,24 @@ await _platformUtilsService.ShowDialogAsync(
await _deviceActionService.HideLoadingAsync();
if (e?.Error != null)
{
// Cozy customization, set custom message for 401 response
// As the stack does not translate error messages and 401 is the most common error
// then we intercept this specific error to translate it on client side
/*
await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(),
AppResources.AnErrorHasOccurred, AppResources.Ok);
/*/
if (e.Error.StatusCode == HttpStatusCode.Unauthorized)
{
var translatedErrorMessage = AppResources.ResourceManager.GetString("CozyInvalidLoginException", AppResources.Culture);
await _platformUtilsService.ShowDialogAsync(translatedErrorMessage, AppResources.AnErrorHasOccurred, AppResources.Ok);
}
else
{
await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(),
AppResources.AnErrorHasOccurred, AppResources.Ok);
}
//*/
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/App/Resources/AppResources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@
<value>Oups, ce n'est pas la bonne adresse. Essayez d'écrire "cozy" avec un "z" !</value>
<comment>Exception message when user mispels Cozy with Cosy</comment>
</data>
<data name="CozyInvalidLoginException" xml:space="preserve">
<value>L'adresse et le mot de passe que vous avez saisi ne semblent pas correspondre</value>
<comment>Exception message when user enter wrong login or password</comment>
</data>
<data name="Credits" xml:space="preserve">
<value>Remerciements</value>
<comment>Title for page that we use to give credit to resources that we use.</comment>
Expand Down
6 changes: 5 additions & 1 deletion src/App/Resources/AppResources.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -197,6 +197,10 @@
<value>Woops, the address is not correct. Try with "cozy" with a "z"!</value>
<comment>Exception message when user mispels Cozy with Cosy</comment>
</data>
<data name="CozyInvalidLoginException" xml:space="preserve">
<value>The Url and password you entered seems to not match</value>
<comment>Exception message when user enter wrong login or password</comment>
</data>
<data name="Credits" xml:space="preserve">
<value>Credits</value>
<comment>Title for page that we use to give credit to resources that we use.</comment>
Expand Down

0 comments on commit 60520fc

Please sign in to comment.