Skip to main content

http_url/
error.rs

1use alloc::string::String;
2use thiserror::Error;
3
4/// Convenience alias for crate results using [`HttpUrlError`].
5pub type Result<T> = core::result::Result<T, HttpUrlError>;
6
7/// Errors that can occur when constructing or building an [`HttpUrl`][crate::HttpUrl].
8///
9/// URL parsing itself is performed by the `url` crate; this enum only covers
10/// the thin layer on top: forwarding [`url::ParseError`] and enforcing the
11/// "http/https only" invariant.
12#[derive(Error, Debug, Clone, PartialEq, Eq)]
13pub enum HttpUrlError {
14    /// A URL string could not be parsed by the `url` crate.
15    #[error("URL parse error: {0}")]
16    Parse(#[from] url::ParseError),
17
18    /// The URL's scheme is not `http` or `https`.
19    #[error("unsupported scheme: '{0}' (only 'http' and 'https' are allowed)")]
20    UnsupportedScheme(String),
21
22    /// Builder validation failed (e.g. a required component was missing).
23    #[error("builder validation error: {0}")]
24    BuilderValidation(String),
25}