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;
     }
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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()));
            }
        }
Esempio n. 5
0
        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);
        }