/// <summary> /// Pipeline handler. Perform any additional behavior and await the <paramref name="next" /> delegate as necessary /// </summary> /// <param name="request">Incoming request</param> /// <param name="cancellationToken">Cancellation token</param> /// <param name="next">Awaitable delegate for the next action in the pipeline. Eventually this delegate represents the handler.</param> /// <returns>Awaitable task returning the <typeparamref name="TResponse" /></returns> public Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { var failures = _validators .Select(x => x.Validate(new ValidationContext <TRequest>(request))) .SelectMany(x => x.Errors) .Where(x => x != null) .ToList(); if (!failures.Any()) { return(next()); } var type = typeof(TResponse); if (!type.IsSubclassOf(typeof(OperationResult))) { var exception = new FluentValidation.ValidationException(failures); throw exception; } var result = Activator.CreateInstance(type); (result as OperationResult).AddError(new MicroserviceEntityValidationException()); foreach (var failure in failures) { (result as OperationResult)?.AppendLog($"{failure.PropertyName}: {failure.ErrorMessage}"); } return(Task.FromResult((TResponse)result)); }
public static void Update(this ModelStateDictionary modelStateDictionary, ValidationException fluentException) { foreach (var validationFailure in fluentException.Errors) { modelStateDictionary[validationFailure.PropertyName].Errors.Add(validationFailure.ErrorMessage); } }
private void AddExceptionToModelErrors(ActionExecutedContext filterContext, Exception exception) { var validationFailure = new ValidationFailure("", exception.Message); var validationException = new ValidationException(new[] { validationFailure }); new Validation.ValidationExceptionHandler() .AddToModel(filterContext, validationException); }
public static void AddValidationErrors(this ModelStateDictionary modelStateDictionary, ValidationException validationException ) { var errorColumns = validationException.Errors.Select(error => new ErrorColumn(error.PropertyName, error.ErrorMessage)); foreach (var errorColumn in errorColumns) { modelStateDictionary.AddModelError(errorColumn.Name, errorColumn.Message); } }
public static void AddValidationErrors(this ModelStateDictionary modelstate, ValidationException validationException) { var validationIssues = validationException.Errors; foreach (var validationIssue in validationIssues) { modelstate.AddModelError(validationIssue.PropertyName, validationIssue.ErrorMessage); } }
private static AjaxError CreateFromValidationException(ValidationException exception, bool includeStackTrace) { var details = includeStackTrace ? exception.ToString() : null; var errors = exception .Errors .GroupBy(failure => failure.PropertyName) .ToDictionary(failures => failures.Key, failures => failures.Select(failure => failure.ErrorMessage)); return new AjaxError(HttpStatusCode.BadRequest, details, Logging.DontLog, errors); }
protected override void BecauseOf() { try { //CustomerCreator.UpdateCustomer(Username, _updateCustomerRequest); } catch (ValidationException exception) { _exception = exception; } }
protected virtual void ThrowHttpResponseException(ValidationException ex) { var errors = new StringBuilder(); foreach (var error in ex.Errors) errors.AppendLine(error.ErrorMessage); var response = ControllerContext.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errors.ToString()); throw new HttpResponseException(response); }
public void AddToModel(ModelStateDictionary modelState, ValidationException exception) { foreach (var error in exception.Errors) modelState.AddModelError(error.PropertyName, error.ErrorMessage); }
public void AddToModel(ActionExecutedContext filter, ValidationException exception) { AddToModel(filter.Controller.ViewData.ModelState, exception); }
public ResponseForProcessingError(ValidationException exception) : base((int)ErrorCodes.ErrorDuringProcessing, "Error during processing", exception.Errors) { }