ic_http_certification/
error.rs

1//! The error module contains types for common errors that may be thrown
2//! by other modules in this crate.
3
4/// HTTP certification result type.
5pub type HttpCertificationResult<T = ()> = Result<T, HttpCertificationError>;
6
7/// HTTP certification error type.
8#[derive(thiserror::Error, Debug, Clone)]
9pub enum HttpCertificationError {
10    /// The URL was malformed and could not be parsed correctly.
11    #[error(r#"Failed to parse url: "{0}""#)]
12    MalformedUrl(String),
13
14    /// Error converting UTF-8 string.
15    #[error(r#"Error converting UTF8 string bytes: "{0}""#)]
16    Utf8ConversionError(#[from] std::string::FromUtf8Error),
17
18    /// Error converting bytes to string.
19    #[error(r#"Wildcard path "{wildcard_path}" is too specific for request path "{request_path}", use a less specific wildcard path"#)]
20    WildcardPathNotValidForRequestPath {
21        /// The wildcard path that was not valid for the request path.
22        wildcard_path: String,
23
24        /// The request path that was not valid for the wildcard path.
25        request_path: String,
26    },
27
28    /// The `IC-CertificateExpression` header in a response did not match the Cel expression used to certify the [HttpResponse](crate::HttpResponse).
29    #[error(r#"The IC-CertificateExpression header in the response did not match the Cel expression used to certify the response. Expected: "{expected}", Actual: "{actual}""#)]
30    CertificateExpressionHeaderMismatch {
31        /// The expected value of the `IC-CertificateExpression` header. This is the Cel expression used to certify the [HttpResponse](crate::HttpResponse).
32        expected: String,
33
34        /// The actual value of the `IC-CertificateExpression` header.
35        actual: String,
36    },
37
38    /// The `IC-CertificateExpression header` was missing from the [HttpResponse](crate::HttpResponse).
39    #[error(r#"The IC-CertificateExpression header was missing from the response. Expected: "{expected}""#)]
40    CertificateExpressionHeaderMissing {
41        /// The expected value of the `IC-CertificateExpression` header. This is the Cel expression used to certify the [HttpResponse](crate::HttpResponse).
42        expected: String,
43    },
44
45    /// The `IC-CertificateExpression` header in a response contained multiple values.
46    #[error(r#"The IC-CertificateExpression header in the response contained multiple values. Expected only one: "{expected}""#)]
47    MultipleCertificateExpressionHeaders {
48        /// The expected value of the `IC-CertificateExpression` header. This is the Cel expression used to certify the [HttpResponse](crate::HttpResponse).
49        expected: String,
50    },
51
52    /// Error converting a number into an HTTP status code.
53    #[error(r#"Error converting number into HTTP status code: "{status_code}""#)]
54    InvalidHttpStatusCode {
55        /// The HTTP status code that was not recognized.
56        status_code: u16,
57    },
58}