Ejemplo n.º 1
0
        private async Task HandleExceptionAsync(HttpContext context, HttpStatusCodeException exception)
        {
            ErrorDetail result;

            context.Response.Clear();
            context.Response.ContentType = "application/json";

            if (exception is HttpStatusCodeException)
            {
                result = new ErrorDetail()
                {
                    Message = exception.Message, StatusCode = (int)exception.StatusCode
                };
                context.Response.StatusCode = result.StatusCode;
                _logger.LogError(String.Format("1-HttpStatusCodeException: {0} - {1}", result.StatusCode, result.Message));
            }
            else
            {
                result = new ErrorDetail()
                {
                    Message = "Runtime Error", StatusCode = (int)HttpStatusCode.BadRequest
                };
                context.Response.StatusCode = result.StatusCode;
                _logger.LogError(String.Format("2-RuntimeError: {0} - {1}", result.StatusCode, result.Message));
            }

            await context.Response.WriteAsync(result.ToString());

            return;
        }
Ejemplo n.º 2
0
        private async Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            ErrorDetail result;

            context.Response.Clear();
            context.Response.ContentType = "application/json";

            result = new ErrorDetail()
            {
                Message = exception.Message, StatusCode = (int)HttpStatusCode.InternalServerError
            };
            context.Response.StatusCode = result.StatusCode;
            _logger.LogInformation(String.Format("3-InternalServerError: {0} - {1}", result.StatusCode, result.Message));

            await context.Response.WriteAsync(result.ToString());

            return;
        }