Exemplo n.º 1
0
        private Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            var errorMessage = GetErrorMessage(exception);

            _errorLogService.AddAsync(new ErrorLog(Guid.NewGuid(), errorMessage, exception.ToString()));

            var result = JsonConvert.SerializeObject(new { error = errorMessage });

            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
            return(context.Response.WriteAsync(result));
        }