A non-2xx response as an error, for code that treats those as failures: .NONE for a 2xx. The
error carries status, title and detail (from an RFC 9457 problem body, the kind the
server sends, when there is one) and the body text, so this reads the body. Release the error
with free_error.
main :: () {
app: App;
defer free_app(*app);
api := test_client(*app);
response, _ := get(api, "/missing");
defer close(*response);
error := error_for_status(*response);
defer free_error(*error);
assert(error.kind == .STATUS && error.status == 404);
}Doesn't run in the browser (skipped on wasm).
error_for_status :: (response: *Client_Response) -> Client_Error
A non-2xx response as an error, for code that treats those as failures: .NONE for a 2xx. The
error carries status, title and detail (from an RFC 9457 problem body, the kind the
server sends, when there is one) and the body text, so this reads the body. Release the error
with free_error.
Parameters
- response: *Client_Response
Returns
main :: () {
app: App;
defer free_app(*app);
api := test_client(*app);
response, _ := get(api, "/missing");
defer close(*response);
error := error_for_status(*response);
defer free_error(*error);
assert(error.kind == .STATUS && error.status == 404);
}Doesn't run in the browser (skipped on wasm).