namespace HomeApi.Extensions; public static class ServiceCallExtensions { public static async Task TryCallAsync( this TService service, Func> 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; } } }