Skip to main content

classify_http_failure

Function classify_http_failure 

Source
pub fn classify_http_failure(status: u16, body: &str) -> CompletionError
Expand description

Classifies a failed HTTP response into a CompletionError.

body must already be bounded and passed through escape_controls. The error keeps exactly that text as its detail. The message never includes it.

The message is the kind’s fixed phrase with (status N) appended. A 401 or 403 is Unavailable, and its message uses the model backend did not accept the credentials in place of the phrase.

The result is always an error. When the body matches a rule, that rule sets the kind. Otherwise a 429 is RateLimited, a 503 or 529 is Overloaded, any other 5xx is ServerError, and any other status except 401 and 403 is Rejected.