Skip to main content

http_acl/
error.rs

1//! Error types for the HTTP ACL library.
2
3use crate::acl::HttpRequestMethod;
4use std::net::{IpAddr, SocketAddr};
5use std::ops::RangeInclusive;
6
7use thiserror::Error;
8
9/// Represents an error that can occur when adding a new allowed or denied entity to
10/// an ACL, or when [`HttpAclBuilder::try_build`](crate::HttpAclBuilder::try_build)
11/// finds the finished configuration inconsistent.
12#[non_exhaustive]
13#[derive(Clone, Debug, Eq, Hash, PartialEq, Error)]
14pub enum AddError {
15    /// The HTTP method is already allowed.
16    #[error("The HTTP method `{0:?}` is already allowed.")]
17    AlreadyAllowedMethod(HttpRequestMethod),
18    /// The HTTP method is already denied.
19    #[error("The HTTP method `{0:?}` is already denied.")]
20    AlreadyDeniedMethod(HttpRequestMethod),
21    /// The host is already allowed.
22    #[error("The host `{0}` is already allowed.")]
23    AlreadyAllowedHost(String),
24    /// The host is already denied.
25    #[error("The host `{0}` is already denied.")]
26    AlreadyDeniedHost(String),
27    /// The port range is already allowed.
28    #[error("The port range `{0:?}` is already allowed.")]
29    AlreadyAllowedPortRange(RangeInclusive<u16>),
30    /// The port range is already denied.
31    #[error("The port range `{0:?}` is already denied.")]
32    AlreadyDeniedPortRange(RangeInclusive<u16>),
33    /// The IP range is already allowed.
34    #[error("The IP range `{0:?}` is already allowed.")]
35    AlreadyAllowedIpRange(RangeInclusive<IpAddr>),
36    /// The IP range is already denied.
37    #[error("The IP range `{0:?}` is already denied.")]
38    AlreadyDeniedIpRange(RangeInclusive<IpAddr>),
39    /// The IP range is not a global IP range.
40    /// This error is returned if the ACL is configured to disallow non-global IP ranges.
41    #[error(
42        "The IP range `{0:?}` is not a global IP range, and non-global IP ranges are not allowed."
43    )]
44    NonGlobalIpRange(RangeInclusive<IpAddr>),
45    /// The header is already allowed.
46    #[error("The header `{0}` is already allowed.")]
47    AlreadyAllowedHeader(String, Option<String>),
48    /// The header is already denied.
49    #[error("The header `{0}` is already denied.")]
50    AlreadyDeniedHeader(String, Option<String>),
51    /// The URL path is already allowed.
52    #[error("The URL path `{0}` is already allowed.")]
53    AlreadyAllowedUrlPath(String),
54    /// The URL path is already denied.
55    #[error("The URL path `{0}` is already denied.")]
56    AlreadyDeniedUrlPath(String),
57    /// The static DNS mapping is already present.
58    #[error("The static DNS mapping for `{0}`-`{1}` is already present.")]
59    AlreadyPresentStaticDnsMapping(String, SocketAddr),
60    /// The trusted static DNS mapping is already present.
61    #[error("The trusted static DNS mapping for `{0}`-`{1}` is already present.")]
62    AlreadyPresentTrustedStaticDnsMapping(String, SocketAddr),
63    /// The entity is not allowed or denied because it is invalid.
64    #[error("The entity `{0}` is not allowed or denied because it is invalid.")]
65    InvalidEntity(String),
66    /// The entity is not unique.
67    #[error("The entity `{0}` is not unique.")]
68    NotUnique(String),
69    /// The entity overlaps with another.
70    #[error("The entity `{0}` overlaps with another.")]
71    Overlaps(String),
72    /// The entity is both allowed and denied.
73    #[error("The entity `{0}` is both allowed and denied.")]
74    BothAllowedAndDenied(String),
75    /// General error with a message.
76    #[error("An error occurred: `{0}`")]
77    Error(String),
78}