internal static ServiceErrorException From(ValidationException exception) { var memberPath = exception.GetMemberPath(exception.ValidationResult?.MemberNames?.FirstOrDefault()); var(errorCode, args) = exception.ValidationAttribute switch { RequiredAttribute _ => (ServiceErrorCode.ParamNotSpecified, new[] { memberPath }), PasswordAttribute _ when TryGetValidationResultProperty(exception.ValidationResult, PasswordValidator.PasswordRequirementsPropertyKey, out var passwordRequirements) => (ServiceErrorCode.ParamNotValid, new object[] { memberPath, passwordRequirements }), _ => (ServiceErrorCode.ParamNotValid, new[] { memberPath }) }; return(new ServiceErrorException(errorCode, args)); }