congressdotgov_rs/api/
error.rs

1//! API Errors.
2
3use std::error::Error;
4use thiserror::Error;
5
6use crate::cdg::CdgError;
7
8/// Error types that can be returned or occur when communicating with the
9/// congress.gov api.
10#[derive(Debug, Error)]
11pub enum ApiError<E>
12where
13    E: Error + Send + Sync + 'static,
14{
15    #[error("Client Error: {}", source)]
16    Client { source: E },
17    #[error("failed to parse url: {}", source)]
18    UrlParse {
19        #[from]
20        source: url::ParseError,
21    },
22    #[error("failed to parse uri: {}", source)]
23    UriParse {
24        #[from]
25        source: http::uri::InvalidUri,
26    },
27    #[error("communication with gitlab: {}", source)]
28    Communication {
29        #[from]
30        source: reqwest::Error,
31    },
32    #[error("HTTP error: {}", status)]
33    Http { status: http::StatusCode },
34    #[error("could not parse data from JSON: {}", source)]
35    DataType {
36        #[from]
37        source: serde_json::Error,
38    },
39    #[error("CDG Error: {}", source)]
40    Cdg {
41        #[from]
42        source: CdgError,
43    },
44}