Skip to main content

Practice ยท 1 of 2

The error envelope that tells no secrets

Implement error_envelope(status, detail=None, field=None) returning {'error': {...}} where: - status is echoed and title comes from this fixed table: 400 bad_request, 404 not_found, 409 conflict, 422 validation_failed, 429 rate_limited, 500 internal_error - field is included only when not None - detail is included when given โ€” EXCEPT for statuses >= 500, where detail is always the generic string 'an unexpected error occurred' (internals must never reach the wire)

Difficulty: advanced

Back to lesson: Practice: Contract Drills