public async Task Invoke(HttpContext httpContext) { try { var authToken = httpContext.Request.Headers["Authorization"].FirstOrDefault(); var authResult = await _authorisationService.Verify(authToken); if (authResult.Valid == false) { _logger.LogError("Request without Authorisation token"); httpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized; await httpContext.Response.WriteAsync("Not authorised to perform this action"); } else { httpContext.Items["Merchant"] = authResult.Merchant; await _next.Invoke(httpContext); } } catch (Exception ex) { _logger.LogCritical(ex, ""); httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; await httpContext.Response.WriteAsync(""); } }