use crate::limit::RateLimit;
use crate::query::ResourceComponent;
use crate::response::{Failures, MessageType};
use std::result;
use thiserror::Error as ThisError;
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug, ThisError)]
#[non_exhaustive]
pub enum Error {
#[error("invalid type name: {name}")]
InvalidTypeName {
name: String,
},
#[error("expected response item of type {expected} but got {got}")]
UnexpectedItem {
expected: MessageType,
got: MessageType,
},
#[error(
"`{value}` cannot be sent as a `{filter}` filter: crossref reads the `,` in it as the start of another filter"
)]
UnsendableFilterValue {
filter: String,
value: String,
},
#[error("{msg}")]
Config {
msg: String,
},
#[error(transparent)]
ReqWest {
#[from]
reqwest: reqwest::Error,
},
#[error("crossref rejected the request: {failures}")]
ValidationFailure {
failures: Failures,
},
#[error("crossref rate limited the request; gave up after {attempts} attempts")]
RateLimited {
attempts: u32,
limit: RateLimit,
},
#[error("Nothing was found for resource `{resource}`")]
ResourceNotFound {
resource: Box<ResourceComponent>,
},
#[error("invalid serde: {error}")]
Serde {
#[from]
error: serde_json::Error,
},
}