Exemplo n.º 1
0
        public void OnException(ExceptionContext context)
        {
            Log.Error(context.Exception, "An unhandled exception occurred during the request");
            client.Notify(context.Exception);

            var code = StatusCodes.Status500InternalServerError;

            if (context.Exception is PolicyCheckFailedException)
            {
                code = StatusCodes.Status403Forbidden;
            }

            // Note: When create the JsonApiException, it sets the status code in the Meta to 500,
            //       which is wrong but we don't have a way to change it and not worth the effort.
            //       The status code of the Result is correct so that is what counts.
            var jsonApiException = JsonApiExceptionFactory.GetException(context.Exception);

            var error  = jsonApiException.GetError();
            var result = new ObjectResult(error)
            {
                StatusCode = code
            };

            context.Result = result;
        }
        public void OnException(ExceptionContext context)
        {
            _logger?.LogError(new EventId(), context.Exception, "An unhandled exception occurred during the request");

            var jsonApiException = JsonApiExceptionFactory.GetException(context.Exception);

            var error  = jsonApiException.GetError();
            var result = new ObjectResult(error);

            result.StatusCode = Convert.ToInt16(error.Status);
            context.Result    = result;
        }