http_request_derive/
error.rs1use bytes::Bytes;
6use http::uri::InvalidUri;
7use snafu::{Location, Snafu};
8use url::Url;
9
10#[derive(Debug, Snafu)]
12#[snafu(visibility(pub(crate)))]
13pub enum Error {
14 #[snafu(display("trying to perform an unauthorized request"))]
16 Unauthorized,
17
18 #[snafu(display("server returned a non-success http status code {status}"))]
20 NonSuccessStatus {
21 status: http::StatusCode,
23
24 data: Bytes,
26 },
27
28 #[snafu(display("could not build http request: {source}"))]
30 BuildRequest {
31 source: http::Error,
33 },
34
35 #[snafu(display("base url {url} cannot be a base"))]
37 UrlCannotBeABase {
38 url: Url,
40 },
41
42 #[snafu(display("couldn't parse uri"))]
44 ParseUri {
45 source: InvalidUri,
47 },
48
49 #[snafu(display("can't create query string: {message}"))]
51 QueryString {
52 message: String,
54 },
55
56 #[cfg(feature = "serde")]
58 #[snafu(display("couldn't build query string from serde url params"))]
59 SerdeUrlParams {
60 source: serde_url_params::Error,
62 },
63
64 #[cfg(feature = "serde")]
66 #[snafu(display("serde json error"))]
67 Json {
68 source: serde_json::Error,
70 },
71
72 #[snafu(display("{message}"))]
74 Custom {
75 message: String,
77
78 location: Location,
80 },
81}
82
83impl Error {
84 #[track_caller]
86 pub fn custom(message: String) -> Self {
87 let location = std::panic::Location::caller();
88
89 Error::Custom {
90 message,
91 location: Location::new(location.file(), location.line(), location.column()),
92 }
93 }
94}