mangadex_api_schema_rust/error.rs
1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6use crate::ResultType;
7
8use crate::RelationshipType;
9
10#[derive(thiserror::Error, Debug)]
11#[non_exhaustive]
12pub enum RelationshipConversionError {
13 #[error("The input relationship type {input} is incompatible with {inner}")]
14 InvalidInputRelationshipType {
15 input: RelationshipType,
16 inner: RelationshipType,
17 },
18 #[error("The {0} related attributes is not found")]
19 AttributesNotFound(RelationshipType),
20}
21
22#[derive(Debug, thiserror::Error, Deserialize, Serialize)]
23#[error("Bad request")]
24#[cfg_attr(feature = "specta", derive(specta::Type))]
25#[non_exhaustive]
26pub struct MangaDexErrorResponse_ {
27 /// Defaults to [`ResultType::Error`]
28 #[serde(default = "ResultType::error")]
29 pub result: ResultType,
30 #[serde(default)]
31 pub errors: Vec<MangaDexError>,
32}
33
34impl Default for MangaDexErrorResponse_ {
35 fn default() -> Self {
36 Self {
37 result: ResultType::Error,
38 errors: Vec::default(),
39 }
40 }
41}
42
43#[derive(Debug, thiserror::Error, PartialEq, Eq, Deserialize, Clone, Serialize, Default)]
44#[error("API error")]
45#[cfg_attr(feature = "specta", derive(specta::Type))]
46#[non_exhaustive]
47pub struct MangaDexError {
48 pub id: Uuid,
49 /// HTTP status code.
50 pub status: u16,
51 /// Error title.
52 pub title: Option<String>,
53 /// Description about the error.
54 pub detail: Option<String>,
55 /// Provides insight into why the request failed.
56 ///
57 /// # Captcha Errors (400)
58 ///
59 /// The error may have been caused by one of the following:
60 ///
61 /// - Captcha challenge result was wrong.
62 /// - The Captcha Verification service was down.
63 /// - Other, refer to the error message and the `errorCode` value.
64 ///
65 /// # Rate Limit, Captcha Required (403)
66 ///
67 /// Some endpoints may require captchas to proceed, in order to slow down automated malicious
68 /// traffic. Legitimate users might also be affected, based on the frequency of write requests
69 /// or due certain endpoints being particularly sensitive to malicious use, such as user signup.
70 ///
71 /// Once an endpoint decides that a captcha needs to be solved,
72 /// a 403 Forbidden response will be returned, with the error code `captcha_required_exception`.
73 /// The sitekey needed for recaptcha to function is provided in both the
74 /// `X-Captcha-Sitekey` header field, as well as in the error context,
75 /// specified as `siteKey` parameter.
76 ///
77 /// The captcha result of the client can either be passed into the repeated original request
78 /// with the `X-Captcha-Result` header or alternatively to the `POST /captcha/solve` endpoint.
79 /// The time a solved captcha is remembered varies across different endpoints and can also be
80 /// influenced by individual client behavior.
81 ///
82 /// Authentication is not required for the `POST /captcha/solve` endpoint, captchas are tracked
83 /// both by client ip and logged in user id. If you are logged in, you want to send the session
84 /// token along, so you validate the captcha for your client ip and user id at the same time,
85 /// but it is not required.
86 // TODO: Use enum representations once the structure of this field is known.
87 // See: https://serde.rs/enum-representations.html
88 pub context: Option<HashMap<String, String>>,
89}