public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (context.ModelState.IsValid)
            {
                return;
            }

            var validationError = context.ModelState
                                  .Keys
                                  .SelectMany(k => context.ModelState[k].Errors)
                                  .Select(e => e.ErrorMessage)
                                  .ToArray();

            var json = new JsonErrorResponse
            {
                Messages = validationError
            };

            context.Result = new BadRequestObjectResult(json);
        }
        public void OnException(ExceptionContext context)
        {
            _logger.LogError(new EventId(context.Exception.HResult),
                             context.Exception,
                             context.Exception.Message);

            var json = new JsonErrorResponse
            {
                Messages = new[] { "An error occured. Try it again." }
            };

            if (_env.IsDevelopment())
            {
                json.DeveloperMessage = context.Exception;
            }

            context.Result = new InternalServerErrorObjectResult(json);
            context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

            context.ExceptionHandled = true;
        }