zendriver_imperva/
error.rs1use zendriver_interception::InterceptionError;
4use zendriver_transport::CallError;
5
6use crate::detection::CaptchaKind;
7
8#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum ImpervaError {
14 #[error("CAPTCHA required but no solver registered: {kind:?}")]
16 CaptchaRequired { kind: CaptchaKind },
17
18 #[error("CAPTCHA solver failed: {0}")]
20 CaptchaSolver(Box<dyn std::error::Error + Send + Sync>),
21
22 #[error("interception hook error: {0}")]
27 Interception(#[from] InterceptionError),
28
29 #[error("call failed: {0}")]
31 Call(#[from] CallError),
32
33 #[error("JS error: {0}")]
35 JsError(String),
36}
37
38#[cfg(test)]
39#[allow(clippy::panic, clippy::unwrap_used)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn display_captcha_required_includes_kind() {
45 let e = ImpervaError::CaptchaRequired {
46 kind: CaptchaKind::HCaptcha,
47 };
48 assert_eq!(
49 e.to_string(),
50 "CAPTCHA required but no solver registered: HCaptcha"
51 );
52 }
53
54 #[test]
55 fn display_js_error_passthrough() {
56 let e = ImpervaError::JsError("bad payload".into());
57 assert_eq!(e.to_string(), "JS error: bad payload");
58 }
59}