236 lines
7.1 KiB
Rust
236 lines
7.1 KiB
Rust
#![allow(unused)]
|
|
use serde::Deserialize;
|
|
use std::fmt;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum ResponseConversionError {
|
|
#[error("failed to convert Attribute")]
|
|
Attribute(#[from] AttributeConversionError),
|
|
#[error("failed to convert Response, got {0}")]
|
|
Response(String),
|
|
#[error("failed to convert Result, got {0}")]
|
|
Result(String),
|
|
#[error("failed to convert ContentType, got {0}")]
|
|
ContentType(String),
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum AttributeConversionError {
|
|
#[error("failed to convert attribute Language, got {0}")]
|
|
Language(String),
|
|
#[error("failed to convert attribute Locale, got {0}")]
|
|
Locale(String),
|
|
#[error("failed to convert attribute LastVolume, got {0}")]
|
|
LastVolume(String),
|
|
#[error("failed to convert attribute LastChapter, got {0}")]
|
|
LastChapter(String),
|
|
#[error("failed to convert attribute CreatedAtDateTime, got {0}")]
|
|
CreatedAtDateTime(String),
|
|
#[error("failed to convert attribute UpdatedAtDateTime, got {0}")]
|
|
UpdatedAtDateTime(String),
|
|
#[error("failed to convert attribute State, got {0}")]
|
|
State(String),
|
|
#[error("failed to convert attribute ContentRating, got {0}")]
|
|
ContentRating(String),
|
|
#[error("failed to convert attribute Status, got {0}")]
|
|
Status(String),
|
|
#[error("failed to convert attribute PublicationDemographic, got {0}")]
|
|
PublicationDemographic(String),
|
|
#[error("failed to convert attribute DataType, got {0}")]
|
|
DataType(String),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum ChapterImageError {
|
|
#[error("chapter image result {0}")]
|
|
Result(String),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum IdQueryResponseError {
|
|
#[error("failed to convert id query response Result")]
|
|
Result,
|
|
#[error("failed to convert id query response Response")]
|
|
Response,
|
|
#[error("failed to convert id query response Data")]
|
|
Data(#[from] ResponseConversionError),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum JsonError {
|
|
#[error("failed to parse json, msg: {0}")]
|
|
Message(String),
|
|
#[error("failed to parse json, unexpected end of file")]
|
|
Eof,
|
|
#[error("failed to parse json, syntax error")]
|
|
Syntax,
|
|
#[error("failed to parse json, expected boolean")]
|
|
ExpectedBoolean,
|
|
#[error("failed to parse json, expected integer")]
|
|
ExpectedInteger,
|
|
#[error("failed to parse json, expected string")]
|
|
ExpectedString,
|
|
#[error("failed to parse json, expected null")]
|
|
ExpectedNull,
|
|
#[error("failed to parse json, expected array")]
|
|
ExpectedArray,
|
|
#[error("failed to parse json, expected array comma")]
|
|
ExpectedArrayComma,
|
|
#[error("failed to parse json, expected array end")]
|
|
ExpectedArrayEnd,
|
|
#[error("failed to parse json, expected map")]
|
|
ExpectedMap,
|
|
#[error("failed to parse json, expected map colon")]
|
|
ExpectedMapColon,
|
|
#[error("failed to parse json, expected map comma")]
|
|
ExpectedMapComma,
|
|
#[error("failed to parse json, expected map end")]
|
|
ExpectedMapEnd,
|
|
#[error("failed to parse json, expected enum")]
|
|
ExpectedEnum,
|
|
#[error("failed to parse json, expected trailing characters")]
|
|
TrailingCharacters,
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum ChapterFeedError {
|
|
#[error("failed to parse json")]
|
|
Serde(#[from] JsonError),
|
|
#[error("failed to convert chapter feed")]
|
|
Conversion(#[from] ChapterFeedConversionError),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum ChapterFeedConversionError {
|
|
#[error("failed to convert chapter feed result, got {0}")]
|
|
Result(String),
|
|
#[error("failed to convert chapter feed response, got {0}")]
|
|
Response(String),
|
|
#[error("failed to convert chapter feed chapter")]
|
|
Chapter(#[from] ChapterConversionError),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum ChapterConversionError {
|
|
#[error("failed to convert chapter DataType, got {0}")]
|
|
DataType(String),
|
|
#[error("failed to convert chapter Id, got {0}")]
|
|
Id(String),
|
|
#[error("failed to convert chapter Relationship")]
|
|
Relationship(#[from] ChapterRelationshipError),
|
|
#[error("failed to convert chapter Attributes")]
|
|
Attributes(#[from] ChapterAttributeConversionError),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum ChapterRelationshipError {
|
|
#[error("failed to convert chapter relationship TypeData, got {0}")]
|
|
TypeData(String),
|
|
#[error("failed to convert chapter relationship Id, got {0}")]
|
|
Id(String),
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum ChapterAttributeConversionError {
|
|
#[error("unable to convert chapter attribute Volume, got {0}")]
|
|
Volume(String),
|
|
#[error("unable to convert chapter attribute Chapter, got {0}")]
|
|
Chapter(String),
|
|
#[error("unable to convert chapter attribute CreatedAt, got {0}")]
|
|
CreatedAt(String),
|
|
#[error("unable to convert chapter attribute UpdatedAt, got {0}")]
|
|
UpdatedAt(String),
|
|
#[error("unable to convert chapter attribute PublishedAt, got {0}")]
|
|
PublishedAt(String),
|
|
#[error("unable to convert chapter attribute TranslatedLanguage, got {0}")]
|
|
TranslatedLanguage(String),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum ChapterImagesError {
|
|
#[error("failed to deserialize chapter images")]
|
|
Image(#[from] ChapterImageError),
|
|
#[error("failed to deserialize chapter images")]
|
|
Content(#[from] ChapterImagesContentError),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum SearchResultError {
|
|
#[error("failed to deserialize json")]
|
|
Serde(#[from] JsonError),
|
|
#[error("failed to convert response to SearchResult")]
|
|
SearchResult(#[from] ResponseConversionError),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum IdQueryResultError {
|
|
#[error("failed to deserialize json")]
|
|
Serde(#[from] JsonError),
|
|
#[error("failed to convert to IdQueryResult")]
|
|
IdQueryResult(#[from] IdQueryResponseError),
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum PublicationDemographicError {
|
|
InvalidValue,
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum ParseLangErr {
|
|
#[error("found invalid lang")]
|
|
Invalid,
|
|
}
|
|
|
|
|
|
#[derive(Debug, Error, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct ApiError {
|
|
pub id: String,
|
|
pub status: u32,
|
|
pub title: String,
|
|
pub detail: String,
|
|
pub context: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Error, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct ChapterImagesContentError {
|
|
pub result: String,
|
|
pub errors: Vec<ApiError>,
|
|
}
|
|
|
|
impl fmt::Display for ApiError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
format!(
|
|
"Api Error:\nid: {}\nstatus: {}\ntitle: {}\ndetail: {}\ncontext{:?}",
|
|
self.id, self.status, self.title, self.detail, self.context
|
|
)
|
|
.fmt(f)
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for ChapterImagesContentError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
format!(
|
|
"chapter images content error:\nresult: {}\nerrors: \n{:#?}",
|
|
self.result, self.errors
|
|
)
|
|
.fmt(f)
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for PublicationDemographicError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::InvalidValue => "InvalidValue".fmt(f),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl serde::de::Error for JsonError {
|
|
fn custom<T: fmt::Display>(msg: T) -> Self {
|
|
JsonError::Message(msg.to_string())
|
|
}
|
|
}
|