1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-12 14:23:26 +00:00

[SG-872] Create generic exception handler for mobile (#2222)

* [SG-872] Add method to handle exception in BaseViewModel

* [SG-872] Code format
This commit is contained in:
André Bispo
2022-12-13 21:53:04 +00:00
committed by GitHub
parent f4b4cfc9de
commit aa0544cd3d
3 changed files with 20 additions and 21 deletions

View File

@@ -1,4 +1,9 @@
using Bit.App.Controls;
using System;
using Bit.App.Abstractions;
using Bit.App.Controls;
using Bit.App.Resources;
using Bit.Core.Abstractions;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Xamarin.Forms;
@@ -8,6 +13,9 @@ namespace Bit.App.Pages
{
private string _pageTitle = string.Empty;
private AvatarImageSource _avatar;
private LazyResolve<IDeviceActionService> _deviceActionService = new LazyResolve<IDeviceActionService>();
private LazyResolve<IPlatformUtilsService> _platformUtilsService = new LazyResolve<IPlatformUtilsService>();
private LazyResolve<ILogger> _logger = new LazyResolve<ILogger>();
public string PageTitle
{
@@ -22,5 +30,16 @@ namespace Bit.App.Pages
}
public ContentPage Page { get; set; }
protected void HandleException(Exception ex, string message = null)
{
Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async () =>
{
await _deviceActionService.Value.HideLoadingAsync();
await _platformUtilsService.Value.ShowDialogAsync(message ?? AppResources.GenericErrorMessage);
}).FireAndForget();
_logger.Value.Exception(ex);
}
}
}