use zendriver_interception::InterceptionError;
use zendriver_transport::CallError;
use crate::detection::CaptchaKind;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ImpervaError {
#[error("CAPTCHA required but no solver registered: {kind:?}")]
CaptchaRequired { kind: CaptchaKind },
#[error("CAPTCHA solver failed: {0}")]
CaptchaSolver(Box<dyn std::error::Error + Send + Sync>),
#[error("interception hook error: {0}")]
Interception(#[from] InterceptionError),
#[error("call failed: {0}")]
Call(#[from] CallError),
#[error("JS error: {0}")]
JsError(String),
}
#[cfg(test)]
#[allow(clippy::panic, clippy::unwrap_used)]
mod tests {
use super::*;
#[test]
fn display_captcha_required_includes_kind() {
let e = ImpervaError::CaptchaRequired {
kind: CaptchaKind::HCaptcha,
};
assert_eq!(
e.to_string(),
"CAPTCHA required but no solver registered: HCaptcha"
);
}
#[test]
fn display_js_error_passthrough() {
let e = ImpervaError::JsError("bad payload".into());
assert_eq!(e.to_string(), "JS error: bad payload");
}
}