public IResponseProvider AddException(Exception ex) { if (!_env.IsProduction()) { _bucket.Exception = ex; } else { AddError(_exResolver.GetInnerMessage(ex)); } return(this); }
public async Task Invoke(HttpContext context) { try { await _next.Invoke(context); } catch (Exception ex) { // Log exception and throw again so it will be handled as supposed from the request's pipeline _logger.LogError(LogEvents.LogExceptionHandler, ex, _exResolver.GetInnerMessage(ex)); throw; } }
string RetrieveErrorDetailsFromHttpContext() { var feature = HttpContext.Features.Get <IExceptionHandlerFeature>(); if (feature?.Error != null) { var msg = _exResolver.GetInnerMessage(feature.Error); _logger.LogError(LogEvents.HomeController, feature.Error, msg); return(msg); } return(null); }
public async Task Invoke(HttpContext context) { try { await _next.Invoke(context); } catch (Exception ex) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; _logger.LogError(LogEvents.ApiExceptionHandler, ex, _exResolver.GetInnerMessage(ex)); await context.Response.WriteAsync(_converter.ConvertToJson(_response .AddException(ex) .Get())); } }
public IEnumerable <string> GetErrors(ModelStateDictionary modelState) { var errors = new List <string>(); var modelErrors = modelState.Values .SelectMany(v => v.Errors); errors.AddRange(modelErrors .Where(e => !string.IsNullOrEmpty(e.ErrorMessage)) .Select(e => e.ErrorMessage)); foreach (var modelError in modelErrors.Where(e => e.Exception != null)) { errors.Add(_exResolver.GetInnerMessage(modelError.Exception)); } return(errors); }