How to handle RFC 9457 problem details in freight APIs
Branch on the HTTP response status and a documented problem type, not on the human-readable error message. Decide separately whether to correct data, retry, or check if the original operation already succeeded.
Keep field errors safe and useful.
RFC 9457 defines a machine-readable error representation including JSON served as application/problem+json. Use documented problem type identifiers and put partner-specific field information in a documented extension. Treat the response status as authoritative for HTTP semantics; do not blindly trust a conflicting status member. Do not put credentials, internal stack traces or private shipment details into the public error body.
A data correction is not a retry.
A synthetic submission receives a documented validation problem identifying the loading site field. Route it to the party that owns that field, and resubmit only after correction. If a separate request times out with no response, first establish whether the provider processed the original request. A missing response is not proof that replay is safe.
Handle partial and non-standard responses.
- Test two differently worded details for one problem type and expect the same operational action.
- Test an unknown type, an empty body and a proxy-generated response. Preserve the HTTP result and route ambiguity to a safe fallback.
- Verify that correlation data is linkable to the original request without exposing the original private payload.