public override MiddlewareData HandleException(MiddlewareData middlewareData, NoSuchHandlerException exception)
        {
            _logger.LogInformation("Cannot find handler for message");
            var message = new BaseOutMessage()
            {
                Text = "Unknown command"
            };

            return(middlewareData.AddRenderMessageFeature(message));
        }
Exemplo n.º 2
0
        public override MiddlewareData HandleException(MiddlewareData middlewareData, Exception exception)
        {
            _logger.LogError(0, exception, "Unexpected error occurred");
            var message = new BaseOutMessage()
            {
                Text = $"Error occured: [{exception.GetType().Name}] {exception.Message}"
            };

            return(middlewareData.AddRenderMessageFeature(message));
        }
Exemplo n.º 3
0
        public Task <FilterResult> FilterAsync(FilterAttribute attribute, MiddlewareData data)
        {
            var principal = data.Features.RequireOne <AuthenticationFeature>().Principal;

            if (!principal.Is​Authenticated())
            {
                var message = new BaseOutMessage()
                {
                    Text = "Unauthorized access"
                };
                var result = FilterResult.BreakExecution(data.AddRenderMessageFeature(message));
                return(Task.FromResult(result));
            }
            return(Task.FromResult(FilterResult.NextFilter(data)));
        }