Skip to main content

crossref/
error.rs

1use crate::query::ResourceComponent;
2use crate::response::MessageType;
3use std::result;
4
5/// A type alias for handling errors throughout crossref.
6pub type Result<T> = result::Result<T, Error>;
7
8/// all different error types this crate uses
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11    /// if an invalid type was requested
12    #[error("invalid type name: {name}")]
13    InvalidTypeName {
14        /// the name of the invalid type
15        name: String,
16    },
17
18    /// if there is a mismatch between the expected return type of the crossref api and this rust client
19    #[error("expected response item of type {expected} but got {got}")]
20    UnexpectedItem {
21        /// the expected type
22        expected: MessageType,
23        /// the received type
24        got: MessageType,
25    },
26    /// a config error
27    #[error("{msg}")]
28    Config {
29        /// the notification
30        msg: String,
31    },
32
33    /// an error that occurred while operating with [reqwest]
34    #[error("{0}")]
35    ReqWest(#[from] reqwest::Error),
36    /// When no message was found but expected
37    #[error("No message found but expected message of type `{expected}`")]
38    MissingMessage {
39        /// the expected type
40        expected: MessageType,
41    },
42    /// When crossref could not find anything
43    #[error("Nothing was found for resource `{resource}`")]
44    ResourceNotFound {
45        /// the resource that was not found
46        resource: Box<ResourceComponent>,
47    },
48    /// if a error in serde occurred
49    #[error("invalid serde: {0}")]
50    Serde(#[from] serde_json::Error),
51}