def json_of

mlbend-huggingface@0.1.1.0 · main.bend:82

import mlbend-huggingface@0.1.1.0/main.bend as MlbendHuggingface
import Base
import bend-kit-http@0.36.0.0/http.bend as Http
import bend-kit-json@0.6.1.1/json.bend as Json

82# The JSON of a response, or the reason there is none.
83def json_of(r: Result<&1, &1, Http.Err, Http.Res>) -> Result<&1, &1, Err, Json.Val>:
84  match r:
85    case Fail{e}:
86      Fail{why_of(e)}
87    case Done{Http.Res{+status, headers, body}}:
88      Bool.pick(Result<&1, &1, Err, Json.Val>, U32.is_lt(status, 400),
89        json_of_body(body),
90        Fail{ErrStatus{status}})

Uses (9)

Used by (1)