36 lines
781 B
Rust
36 lines
781 B
Rust
![]() |
use crate::{LibraryError, LibraryResult};
|
||
|
use serde::Deserialize;
|
||
|
|
||
|
#[derive(serde::Deserialize)]
|
||
|
#[serde(rename_all = "snake_case")]
|
||
|
pub enum APIErrorType {
|
||
|
InvalidGrant,
|
||
|
}
|
||
|
|
||
|
#[derive(Deserialize)]
|
||
|
pub(crate) struct APIError {
|
||
|
pub error: APIErrorType,
|
||
|
pub error_description: String,
|
||
|
}
|
||
|
|
||
|
// mostly used in the aggregated endpoint
|
||
|
#[derive(serde::Deserialize)]
|
||
|
#[serde(untagged)]
|
||
|
pub(crate) enum APIResult<T> {
|
||
|
APIError(APIError),
|
||
|
Okay(T),
|
||
|
}
|
||
|
|
||
|
impl<T> Into<LibraryResult<T>> for APIResult<T> {
|
||
|
fn into(self) -> LibraryResult<T> {
|
||
|
match self {
|
||
|
APIResult::APIError(err) => {
|
||
|
return Err(LibraryError::from(err));
|
||
|
}
|
||
|
APIResult::Okay(res) => {
|
||
|
return Ok(res);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|