* fix: crash on unavailable source api the screen not updating because of errors * Change temperature format if null Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
23 lines
584 B
C#
23 lines
584 B
C#
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;
|
|
}
|
|
}
|
|
} |