open_api_hydra/apis/
mod.rs

1use reqwest;
2use serde_json;
3use std::error;
4use std::fmt;
5
6#[derive(Debug, Clone)]
7pub struct ResponseContent<T> {
8    pub status: reqwest::StatusCode,
9    pub content: String,
10    pub entity: Option<T>,
11}
12
13#[derive(Debug)]
14pub enum Error<T> {
15    Reqwest(reqwest::Error),
16    Serde(serde_json::Error),
17    Io(std::io::Error),
18    ResponseError(ResponseContent<T>),
19}
20
21impl <T> fmt::Display for Error<T> {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        let (module, e) = match self {
24            Error::Reqwest(e) => ("reqwest", e.to_string()),
25            Error::Serde(e) => ("serde", e.to_string()),
26            Error::Io(e) => ("IO", e.to_string()),
27            Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
28        };
29        write!(f, "error in {}: {}", module, e)
30    }
31}
32
33impl <T: fmt::Debug> error::Error for Error<T> {
34    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
35        Some(match self {
36            Error::Reqwest(e) => e,
37            Error::Serde(e) => e,
38            Error::Io(e) => e,
39            Error::ResponseError(_) => return None,
40        })
41    }
42}
43
44impl <T> From<reqwest::Error> for Error<T> {
45    fn from(e: reqwest::Error) -> Self {
46        Error::Reqwest(e)
47    }
48}
49
50impl <T> From<serde_json::Error> for Error<T> {
51    fn from(e: serde_json::Error) -> Self {
52        Error::Serde(e)
53    }
54}
55
56impl <T> From<std::io::Error> for Error<T> {
57    fn from(e: std::io::Error) -> Self {
58        Error::Io(e)
59    }
60}
61
62pub fn urlencode<T: AsRef<str>>(s: T) -> String {
63    ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
64}
65
66pub mod admin_api;
67pub mod public_api;
68
69pub mod configuration;