-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regenerated using OpenAPI Generator Version 5.1.0
- Loading branch information
Showing
6 changed files
with
64 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,65 @@ | ||
use hyper; | ||
use serde; | ||
use serde_json; | ||
use std::error; | ||
use std::fmt; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ResponseContent<T> { | ||
pub status: reqwest::StatusCode, | ||
pub content: String, | ||
pub entity: Option<T>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Error<T> { | ||
UriError(hyper::error::UriError), | ||
Hyper(hyper::Error), | ||
Reqwest(reqwest::Error), | ||
Serde(serde_json::Error), | ||
ApiError(ApiError<T>), | ||
Io(std::io::Error), | ||
ResponseError(ResponseContent<T>), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ApiError<T> { | ||
pub code: hyper::StatusCode, | ||
pub content: Option<T>, | ||
} | ||
|
||
impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error<T> | ||
where T: serde::Deserialize<'de> { | ||
fn from(e: (hyper::StatusCode, &'de [u8])) -> Self { | ||
if e.1.len() == 0 { | ||
return Error::ApiError(ApiError{ | ||
code: e.0, | ||
content: None, | ||
}); | ||
} | ||
match serde_json::from_slice::<T>(e.1) { | ||
Ok(t) => Error::ApiError(ApiError{ | ||
code: e.0, | ||
content: Some(t), | ||
}), | ||
Err(e) => { | ||
Error::from(e) | ||
} | ||
} | ||
impl <T> fmt::Display for Error<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let (module, e) = match self { | ||
Error::Reqwest(e) => ("reqwest", e.to_string()), | ||
Error::Serde(e) => ("serde", e.to_string()), | ||
Error::Io(e) => ("IO", e.to_string()), | ||
Error::ResponseError(e) => ("response", format!("status code {}", e.status)), | ||
}; | ||
write!(f, "error in {}: {}", module, e) | ||
} | ||
} | ||
|
||
impl <T: fmt::Debug> error::Error for Error<T> { | ||
fn source(&self) -> Option<&(dyn error::Error + 'static)> { | ||
Some(match self { | ||
Error::Reqwest(e) => e, | ||
Error::Serde(e) => e, | ||
Error::Io(e) => e, | ||
Error::ResponseError(_) => return None, | ||
}) | ||
} | ||
} | ||
|
||
impl<T> From<hyper::Error> for Error<T> { | ||
fn from(e: hyper::Error) -> Self { | ||
return Error::Hyper(e) | ||
impl <T> From<reqwest::Error> for Error<T> { | ||
fn from(e: reqwest::Error) -> Self { | ||
Error::Reqwest(e) | ||
} | ||
} | ||
|
||
impl<T> From<serde_json::Error> for Error<T> { | ||
impl <T> From<serde_json::Error> for Error<T> { | ||
fn from(e: serde_json::Error) -> Self { | ||
return Error::Serde(e) | ||
Error::Serde(e) | ||
} | ||
} | ||
|
||
mod request; | ||
impl <T> From<std::io::Error> for Error<T> { | ||
fn from(e: std::io::Error) -> Self { | ||
Error::Io(e) | ||
} | ||
} | ||
|
||
pub fn urlencode<T: AsRef<str>>(s: T) -> String { | ||
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() | ||
} | ||
|
||
|
||
pub mod configuration; | ||
pub mod client; |
Oops, something went wrong.