viaduct/
error.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error("[no-sentry] Illegal characters in request header '{0}'")]
8    RequestHeaderError(crate::HeaderName),
9
10    #[error("[no-sentry] Backend error: {0}")]
11    BackendError(String),
12
13    #[error("[no-sentry] Network error: {0}")]
14    NetworkError(String),
15
16    #[error("The rust-components network backend must be initialized before use!")]
17    BackendNotInitialized,
18
19    #[error("Backend already initialized.")]
20    SetBackendError,
21
22    /// Note: we return this if the server returns a bad URL with
23    /// its response. This *probably* should never happen, but who knows.
24    #[error("[no-sentry] URL Parse Error: {0}")]
25    UrlError(#[source] url::ParseError),
26
27    #[error("[no-sentry] Validation error: URL does not use TLS protocol.")]
28    NonTlsUrl,
29}
30
31impl From<url::ParseError> for Error {
32    fn from(u: url::ParseError) -> Self {
33        Error::UrlError(u)
34    }
35}
36
37/// This error is returned as the `Err` result from
38/// [`Response::require_success`].
39///
40/// Note that it's not a variant on `Error` to distinguish between errors
41/// caused by the network, and errors returned from the server.
42#[derive(thiserror::Error, Debug, Clone)]
43#[error("Error: {method} {url} returned {status}")]
44pub struct UnexpectedStatus {
45    pub status: u16,
46    pub method: crate::Method,
47    pub url: url::Url,
48}