Skip to main content

libpixiv/
lib.rs

1use reqwest_middleware::reqwest::StatusCode;
2use std::error::Error;
3use strum::Display;
4
5/// Core client functionality
6pub mod client;
7/// Illustration endpoints for the client
8pub mod illusts;
9/// API data models
10pub mod models;
11/// Search endpoints for the client
12pub mod search;
13/// Token store for the client
14pub mod tokens;
15/// Ugora (GIF) endpoints for the client
16pub mod ugoira;
17/// User endpoints for the client
18pub mod users;
19
20#[cfg(feature = "clap")]
21pub use clap;
22pub use reqwest_middleware::reqwest;
23#[cfg(feature = "sqlx")]
24pub use sqlx;
25
26/// Pixiv application errors
27#[derive(Debug, Clone, Display)]
28pub enum PixivAppError {
29    /// (404) the requested content does not exist
30    #[strum(to_string = "Requested endpoint not found")]
31    TargetNotFound,
32    /// (400) the request failed, probably because it is malformed
33    #[strum(to_string = "Request failed, check request parameters!")]
34    RequestFailed,
35    /// (403) the request is not authorized and we need to log in
36    #[strum(to_string = "Request failed because of missing authorization!")]
37    MissingLogin,
38    /// (429) we've hit the rate limit and need to wait a bit (no, we do not get headers that tell
39    /// us how long we should wait)
40    #[strum(to_string = "Too many requests, try again later")]
41    RateLimitReached,
42    /// (everything else) the request was sent and the server responded, but we dont know what
43    /// exactly the issue is
44    #[strum(to_string = "{0}")]
45    UnhandledStatus(StatusCode),
46    /// no one knows what went wrong
47    #[strum(to_string = "An unknown error happened and no data was returned.")]
48    Unknown,
49}
50
51impl Error for PixivAppError {}