Skip to content

Align endpoint error JSON to Weblate/DRF conventions #161

Description

@whisper67265

Problem

The add-or-update endpoint returned validation errors in a custom JSON shape (message plus a metadata bag with field, language, and drf_code) instead of the DRF standardized error format used elsewhere in Weblate. Clients could not rely on consistent detail/attr/code fields or the type: validation_error envelope for HTTP 400 responses.

Acceptance Criteria

  • HTTP 400 validation responses include type: validation_error and an errors list where each entry has code, detail, and attr
  • Field and nested language context is expressed via dot-separated attr paths (e.g. add_or_update.zh_Hans) rather than a metadata bag on API validation errors
  • AddOrUpdateRequestSerializer exposes standardized_errors flattened from DRF validation detail via flatten_validation_detail
  • Service-layer helpers (to_error_dict, append_error) still support an optional metadata bag for Celery task and per-submodule results

Implementation Notes

  • Introduced to_error_entry, attr_for_field, and flatten_validation_detail in errors.py to build and flatten DRF-standard entries; BoostEndpointError.to_dict() now emits detail/attr instead of message/metadata
  • Serializer validation accumulates ErrorDetail objects with boost error codes in nested field-keyed detail, replacing parallel _custom_validation_errors / structured_errors lists
  • AddOrUpdateView delegates to serializer.is_valid(raise_exception=True) so DRF's exception handler produces the standardized response envelope

References

  • src/boost_weblate/endpoint/errors.py
  • src/boost_weblate/endpoint/serializers.py
  • src/boost_weblate/endpoint/tasks.py
  • src/boost_weblate/endpoint/views.py
  • tests/endpoint/test_errors.py
  • tests/endpoint/test_serializers.py
  • tests/endpoint/test_views.py

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions