use std::error::Error;
use std::fmt;
#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ErrorResponse {
pub code: u16,
pub errors: Vec<ErrorResponseItem>,
pub message: String,
}
impl ErrorResponse {
pub fn is_retriable(&self) -> bool {
matches!(self.code, 408 | 429 | 500..=599)
}
}
impl fmt::Display for ErrorResponse {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.message.fmt(f)
}
}
impl Error for ErrorResponse {}
#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ErrorResponseItem {
pub domain: String,
pub location: Option<String>,
pub location_type: Option<String>,
pub message: String,
pub reason: String,
}
impl fmt::Display for ErrorResponseItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.message.fmt(f)
}
}
#[derive(serde::Deserialize)]
pub(crate) struct ErrorWrapper {
pub(crate) error: ErrorResponse,
}