-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCommunicationHubFilter.cs
More file actions
39 lines (33 loc) · 1.26 KB
/
CommunicationHubFilter.cs
File metadata and controls
39 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Net;
using System.Threading.Tasks;
using ManagedCode.Communication.Extensions.Extensions;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace ManagedCode.Communication.Extensions;
public class CommunicationHubFilter : IHubFilter
{
private readonly ILogger<CommunicationHubFilter> _logger;
private readonly IOptions<CommunicationOptions> _options;
public CommunicationHubFilter(ILogger<CommunicationHubFilter> logger, IOptions<CommunicationOptions> options)
{
_logger = logger;
_options = options;
}
public async ValueTask<object?> InvokeMethodAsync(HubInvocationContext invocationContext,
Func<HubInvocationContext, ValueTask<object?>> next)
{
try
{
return await next(invocationContext);
}
catch (Exception ex)
{
_logger.LogError(ex, invocationContext.Hub.GetType().Name + "." + invocationContext.HubMethodName);
if (_options.Value.ShowErrorDetails)
return Result.Fail(HttpStatusCode.InternalServerError, ex.Message);
return Result.Fail(HttpStatusCode.InternalServerError, nameof(HttpStatusCode.InternalServerError));
}
}
}