Question
Http.Error.BadStatus loses response body on non-success HTTP statuses
Lax Moss
0 reputation · 22 Jul 2022, 07:20 UTC
137.7K views0
Goal
Retrieve the server‑sent response body when an Elm http request results in a non‑2xx status, so that error messages returned as JSON can be decoded and displayed.
Constraints and uncertainty
- The
Http.Error.BadStatusconstructor carries only the integer status code; the response body, headers, and raw payload are not attached. - Standard decoders such as
expectJsonandexpectStringare invoked only for successful responses, leaving server error bodies inaccessible through the normalHttppath. - It is unclear whether the elm/http library can be configured to expose the body alongside
BadStatuswithout abandoning the built‑in success/failure routing, or if users must always drop to lower‑level APIs likeexpectStringResponse.
Open questions
- Can elm/http be extended or configured to attach the raw response body (or a decoded JSON payload) to
BadStatusvalues? - What are the practical trade‑offs of switching from the standard
expectJson/expectStringflow toexpectStringResponsefor handling non‑2xx responses? - Does the library provide a helper or pattern that allows decoding JSON bodies from error statuses while preserving the existing
Http.Errorunion type?