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    /// Error message
12    pub error: String,
13
14    /// Additional details of this error. Schema depends on the error itself.
15    pub details: Option<Value>,
16}
17
18impl Display for FirecrawlAPIError {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        if let Some(details) = self.details.as_ref() {
21            write!(f, "{} ({})", self.error, details)
22        } else {
23            write!(f, "{}", self.error)
24        }
25    }
26}
27
28#[derive(Error, Debug)]
29pub enum FirecrawlError {
30    #[error("{0} failed: HTTP error {1}: {2}")]
31    HttpRequestFailed(String, u16, String),
32    #[error("{0} failed: HTTP error: {1}")]
33    HttpError(String, reqwest::Error),
34    #[error("Failed to parse response as text: {0}")]
35    ResponseParseErrorText(reqwest::Error),
36    #[error("Failed to parse response: {0}")]
37    ResponseParseError(serde_json::Error),
38    #[error("{0} failed: {1}")]
39    APIError(String, FirecrawlAPIError),
40    #[error("Crawl job failed: {0}")]
41    CrawlJobFailed(String, CrawlStatus),
42    #[error("Crawl job cancelled")]
43    CrawlJobCancelled(CrawlStatus),
44    #[error("Batch scrape job failed: {0}")]
45    BatchScrapeJobFailed(String),
46}