pub enum Error {
InvalidProject {
message: String,
},
InvalidApiKey {
message: String,
},
InvalidAmount {
message: String,
},
InvalidOrderId {
message: String,
},
InvalidPaymentMethod {
message: String,
},
EncodeJson {
message: String,
source: Error,
},
DecodeJson {
message: String,
source: Error,
},
BuildRequest {
source: ParseError,
},
Api {
status: StatusCode,
body: String,
},
RequestFailed {
message: String,
source: BoxError,
},
RequestFailedAfterRetries {
message: String,
source: BoxError,
},
ResponseTooLarge {
limit: usize,
},
}Expand description
Every error the SDK can produce.
Variants§
InvalidProject
The project slug is empty. Triggered by crate::Client::do_request
before any network call.
InvalidApiKey
The API key is empty. Triggered by crate::Client::do_request
before any network call.
InvalidAmount
amount was zero or negative.
InvalidOrderId
order_id was empty.
InvalidPaymentMethod
A payment method outside the supported set was used. Currently unused
because the typed crate::PaymentMethod enum makes invalid values
unrepresentable, but kept here so future runtime checks have a slot
to land in.
EncodeJson
serde_json refused to encode the request body.
DecodeJson
serde_json refused to decode the response body.
BuildRequest
The configured base URL combined with a path did not parse as a URL.
Fields
source: ParseErrorApi
The API returned a non-2xx response.
body is the raw response body decoded as UTF-8 with lossy
substitution. Use Error::api_status to read the status code
programmatically.
RequestFailed
A request hit a permanent transport-level failure (TLS, invalid URL after the builder accepted it, response too large, …).
RequestFailedAfterRetries
The retry loop ran out of attempts. source is the last transient
failure observed.
ResponseTooLarge
The response body exceeded the configured size cap. Returned without fully buffering the offending response.
Implementations§
Source§impl Error
impl Error
Sourcepub fn api_status(&self) -> Option<StatusCode>
pub fn api_status(&self) -> Option<StatusCode>
Return the HTTP status when this is an Error::Api, otherwise
None. Handy for branch logic without having to match on the full
enum.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()