public ValidationError(ValidationErrorResult validationResult) : base(validationResult.ErrorMessage) { this.errorCode = validationResult.ErrorCode; this.ErrorMessage = validationResult.ErrorMessage; this.Violations = validationResult.Errors; }
public static void ThrowIfNotValid(ValidationErrorResult validationResult) { if (!validationResult.IsValid) { throw new ValidationError(validationResult); } }
public ValidationError(ValidationErrorResult validationResult) : base(validationResult.ErrorMessage) { this.errorCode = validationResult.ErrorCode; this.ErrorMessage = validationResult.ErrorMessage; this.Violations = validationResult.Errors; }
/// <summary> /// Converts the validation result to an error result which will be serialized by SStack in a clean and human-readable way. /// </summary> /// <param name="result">The validation result</param> /// <returns></returns> public static ValidationErrorResult ToErrorResult(this ValidationResult result) { var validationResult = new ValidationErrorResult(); foreach (var error in result.Errors) validationResult.Errors.Add(new ValidationErrorField(error.ErrorCode, error.PropertyName, error.ErrorMessage, error.AttemptedValue)); return validationResult; }
/// <summary> /// Merge errors from another <see cref="ValidationErrorResult"/> /// </summary> /// <param name="result"></param> public void Merge(ValidationErrorResult result) { if (result != null) { foreach (var e in result.Errors) { Errors.Add(e); } } }
public static object CreateErrorResponse(object request, ValidationErrorResult validationError) { var responseStatus = validationError.ToResponseStatus(); var errorResponse = CreateErrorResponse( request, new ValidationError(validationError), responseStatus); return errorResponse; }
public static void ThrowIfNotValid(ValidationErrorResult validationResult) { if (!validationResult.IsValid) { throw new ValidationError(validationResult); } }
/// <summary> /// Merge errors from another <see cref="ValidationErrorResult"/> /// </summary> /// <param name="result"></param> public void Merge(ValidationErrorResult result) { if (result != null) { foreach (var e in result.Errors) { Errors.Add(e); } } }