> For the complete documentation index, see [llms.txt](https://changelog.airship.co.uk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://changelog.airship.co.uk/september-2024/02-09-2024-fix-discard-invalid-data-rule.md).

# 02/09/2024 Fix Discard Invalid Data Rule

## :bug: Bug Fix

Nested errors that should be discarded can cause the request to fail.

1. **Validation Error Reading**:
   * The refactored code now reads validation errors across the entire array, not just focusing on deep nested fields. This ensures that all validation errors are considered during processing.
2. **Required vs. Optional Fields**:
   * For each field with a validation error, the code checks its associated validation rules.
   * If a field is marked as required, it will **not** be removed from the request. Instead, an exception will be thrown, making it clear that the field is both required and invalid.
   * Optional fields that have validation errors will be removed from the request to ensure the request remains valid.
3. **Debugging and Error Identification**:
   * With this refactor, it is now easier to debug and identify invalid fields. If the `discard_invalid_data` rule is applied and an exception is thrown, it will clearly indicate that the issue lies with a required field.

:woman\_technologist: Mya Skylar
