Skip to main content

zendriver_datadome/
error.rs

1//! DataDome-bypass errors.
2
3use zendriver_interception::InterceptionError;
4use zendriver_transport::CallError;
5
6/// Error returned by [`DataDomeBypass`] operations. Faults only — flow
7/// terminals (cleared / blocked / timed-out / already-clear) are
8/// [`ClearanceOutcome`] variants, not errors.
9///
10/// [`DataDomeBypass`]: crate::bypass::DataDomeBypass
11/// [`ClearanceOutcome`]: crate::bypass::ClearanceOutcome
12#[derive(Debug, thiserror::Error)]
13#[non_exhaustive]
14pub enum DataDomeError {
15    /// CAPTCHA surface detected, but no `on_captcha` solver was registered.
16    #[error("CAPTCHA surface detected but no solver registered")]
17    CaptchaRequired,
18
19    /// User-supplied CAPTCHA solver returned an error.
20    #[error("CAPTCHA solver failed: {0}")]
21    CaptchaSolver(Box<dyn std::error::Error + Send + Sync>),
22
23    /// Fetch-domain interception hook failed at startup.
24    #[error("interception hook error: {0}")]
25    Interception(#[from] InterceptionError),
26
27    /// CDP transport / call error.
28    #[error("call failed: {0}")]
29    Call(#[from] CallError),
30
31    /// In-page evaluator raised or returned an unexpected payload shape.
32    #[error("JS error: {0}")]
33    JsError(String),
34}
35
36#[cfg(test)]
37#[allow(clippy::panic, clippy::unwrap_used)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn display_captcha_required() {
43        assert_eq!(
44            DataDomeError::CaptchaRequired.to_string(),
45            "CAPTCHA surface detected but no solver registered"
46        );
47    }
48
49    #[test]
50    fn display_js_error_passthrough() {
51        assert_eq!(
52            DataDomeError::JsError("bad payload".into()).to_string(),
53            "JS error: bad payload"
54        );
55    }
56}