Added try catch and logging to Image.OnLoaded methods

This commit is contained in:
Dinis Vieira 2024-03-27 21:45:14 +00:00
parent 583fd6ba1e
commit 6b15bfce12
No known key found for this signature in database
GPG Key ID: 9389160FF6C295F3
2 changed files with 36 additions and 9 deletions

View File

@ -1,4 +1,6 @@
namespace Bit.App.Controls
using Bit.Core.Services;
namespace Bit.App.Controls
{
public partial class AuthenticatorViewCell : BaseCipherViewCell
{
@ -16,14 +18,26 @@
if (Handler?.MauiContext == null) { return; }
if (_iconImage?.Source == null) { return; }
var result = await _iconImage.Source.GetPlatformImageAsync(Handler.MauiContext);
if (result == null)
try
{
var result = await _iconImage.Source.GetPlatformImageAsync(Handler.MauiContext);
if (result == null)
{
Icon_Error(sender, e);
}
else
{
Icon_Success(sender, e);
}
}
catch (InvalidOperationException) //Can occur with incorrect/malformed uris
{
Icon_Error(sender, e);
}
else
catch(Exception ex)
{
Icon_Success(sender, e);
LoggerHelper.LogEvenIfCantBeResolved(ex);
Icon_Error(sender, e);
}
}
}

View File

@ -1,6 +1,7 @@
using System.Windows.Input;
using Bit.App.Abstractions;
using Bit.App.Pages;
using Bit.Core.Services;
using Bit.Core.Utilities;
namespace Bit.App.Controls
@ -46,14 +47,26 @@ namespace Bit.App.Controls
if (Handler?.MauiContext == null) { return; }
if (_iconImage?.Source == null) { return; }
var result = await _iconImage.Source.GetPlatformImageAsync(Handler.MauiContext);
if (result == null)
try
{
var result = await _iconImage.Source.GetPlatformImageAsync(Handler.MauiContext);
if (result == null)
{
Icon_Error(sender, e);
}
else
{
Icon_Success(sender, e);
}
}
catch (InvalidOperationException) //Can occur with incorrect/malformed uris
{
Icon_Error(sender, e);
}
else
catch(Exception ex)
{
Icon_Success(sender, e);
LoggerHelper.LogEvenIfCantBeResolved(ex);
Icon_Error(sender, e);
}
}
}