fix: crash on unavailable source api (#4)
* 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>
This commit was merged in pull request #4.
This commit is contained in:
22
HomeApi/Extensions/MediatorExtensions.cs
Normal file
22
HomeApi/Extensions/MediatorExtensions.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using MediatR;
|
||||
|
||||
namespace HomeApi.Extensions;
|
||||
|
||||
public static class MediatorExtensions
|
||||
{
|
||||
public static async Task<T?> TrySendAsync<T>(
|
||||
this IMediator mediator,
|
||||
IRequest<T> request,
|
||||
CancellationToken cancellationToken) where T : class
|
||||
{
|
||||
try
|
||||
{
|
||||
return await mediator.Send(request, cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException) { throw; }
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user