firecrawl_sdk/
error.rs

1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use thiserror::Error;
6
7use crate::crawl::CrawlStatus;
8
9#[derive(Debug, Deserialize, Serialize, Clone)]
10pub struct FirecrawlAPIError {
11    /// Always false.
12    pub success: bool,
13
14    /// Error message
15    pub error: String,
16
17    /// Additional details of this error. Schema depends on the error itself.
18    pub details: Option<Value>,
19}
20
21impl Display for FirecrawlAPIError {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        if let Some(details) = self.details.as_ref() {
24            write!(f, "{} ({})", self.error, details)
25        } else {
26            write!(f, "{}", self.error)
27        }
28    }
29}
30
31#[derive(Error, Debug)]
32pub enum FirecrawlError {
33    #[error("{0} failed: HTTP error {1}: {2}")]
34    HttpRequestFailed(String, u16, String),
35    #[error("{0} failed: HTTP error: {1}")]
36    HttpError(String, reqwest::Error),
37    #[error("Failed to parse response as text: {0}")]
38    ResponseParseErrorText(reqwest::Error),
39    #[error("Failed to parse response: {0}")]
40    ResponseParseError(serde_json::Error),
41    #[error("{0} failed: {1}")]
42    APIError(String, FirecrawlAPIError),
43    #[error("Crawl job failed: {0}")]
44    CrawlJobFailed(String, CrawlStatus),
45}