vanhecke/celmex/2.0.0

NOTE: the latest version is 3.0.0

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/vanhecke/celmex is gone (deleted or private); Software Heritage not asked yet (this run's --swh-calls were used up); no fork with the same repo name found; no cached copy. Use another version.

Details

Cortex.Error

Errors produced by Cortex.Client.send. Wraps the four standard elm/http failure modes and adds a normalized decoding of the four different error envelopes the Cortex API returns.

type Error
= NetworkError
| Timeout
| BadStatus Int (Maybe ApiError)
| BadBody String
| BadUrl String

What can go wrong when sending a request.

  • NetworkError — the request never reached the server.
  • Timeout — no response within the configured timeout.
  • BadStatus code maybeApiError — the server responded with a 4xx/5xx. The payload is parsed into an ApiError if it matches one of the known envelope shapes; otherwise it's Nothing.
  • BadBody detail — a 2xx response whose body did not match the decoder.
  • BadUrl url — the URL was rejected by elm/http before dispatch.
type alias ApiError =
{ errCode : Maybe String
, errMsg : String
, errExtra : Maybe Value
}

A server-reported error, normalized across the four envelope shapes the Cortex API is known to return. errCode and errExtra are optional because not every envelope includes them.

decodeApiError : String -> Maybe ApiError

Try multiple known error envelope shapes, in priority order. Returns the first successful parse as an ApiError.

The body is parsed to a Decode.Value once up-front; each candidate decoder is then attempted against that parsed value rather than re-parsing the original string. Matters on large error bodies.