HTTP plumbing for Brave Search: one HttpError shape with a readable message, and send.
Functions
error-detail
fn (body: Any): Any
Brave's error text from a response body, or null. Understands {error: {detail}}, {error: {message}}, {error}, and plain {message} or string bodies. Exposed for testing.
error-message
fn (status: Int, body: Any): Str
Brave API error <status>: <detail>, or without the detail when the body has none. Exposed for testing.
http-error
fn (response: ::hot::http/HttpResponse): HttpError
Build the HttpError for a non-2xx response. Exposed for testing.
send
fn (request: ::hot::http/HttpRequest): Any
Send request and unwrap: the decoded JSON body on 2xx, an Err carrying HttpError otherwise, or the transport Err.
text-or-null
fn (value: Any): Any
Types
HttpError
HttpError type {
status: Int,
message: Str,
headers: Map,
body: Any
}
A non-2xx Brave response. message is readable text such as Brave API error 422: Unable to validate request parameter(s); body keeps the raw response.