fix: crash on unavailable source api

the screen not updating because of errors
This commit is contained in:
2025-08-14 17:02:48 +02:00
parent 8284ae9695
commit f0344bd3ba
11 changed files with 336 additions and 96 deletions

View File

@@ -0,0 +1,23 @@
namespace HomeApi.Extensions;
public static class ServiceCallExtensions
{
public static async Task<TResult?> TryCallAsync<TService, TResult>(
this TService service,
Func<TService, Task<TResult>> action,
ILogger logger,
string errorMessage)
where TResult : class?
{
try
{
return await action(service);
}
catch (OperationCanceledException) { throw; }
catch (Exception exception)
{
logger.LogError(exception, errorMessage);
return null;
}
}
}