Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(sdk): raise on an unsuccessful search response
PhantomInTheWiref000f970d6f1
diff --git a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_legal_regulatory_search.py b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_legal_regulatory_search.pyindex f456b3660..8e1a12f71 100644--- a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_legal_regulatory_search.py+++ b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_legal_regulatory_search.py@@ -4,6 +4,7 @@ import pytestfrom firecrawl.v2.client import FirecrawlClientfrom firecrawl.v2.client_async import AsyncFirecrawlClient+from firecrawl.v2.utils.error_handler import FirecrawlErrorRESPONSE = {@@ -21,10 +22,13 @@ RESPONSE = {}-def _response():+FAILED = {"success": False, "error": "Search failed"}+++def _response(body=RESPONSE):response = Mock()response.status_code = 200- response.json.return_value = RESPONSE+ response.json.return_value = bodyreturn response@@ -79,3 +83,24 @@ async def test_async_legal_regulatory_search_posts_query_and_k():"/v2/search/gov", {"query": "food labeling requirements", "k": 5})assert result.data.web[0].url.startswith("https://www.ecfr.gov/")+++def test_legal_regulatory_search_raises_on_unsuccessful_body():+ transport = Mock()+ transport.post.return_value = _response(FAILED)+ client = FirecrawlClient.__new__(FirecrawlClient)+ client.http_client = transport++ with pytest.raises(FirecrawlError, match="Search failed"):+ client.legal_regulatory_search("zoning variance")+++async def test_async_legal_regulatory_search_raises_on_unsuccessful_body():+ transport = Mock()+ transport.post = AsyncMock(return_value=_response(FAILED))+ client = AsyncFirecrawlClient.__new__(AsyncFirecrawlClient)+ client.async_http_client = transport++ with pytest.raises(FirecrawlError, match="Search failed"):+ await client.legal_regulatory_search("zoning variance")diff --git a/apps/python-sdk/firecrawl/v2/methods/aio/legal_regulatory.py b/apps/python-sdk/firecrawl/v2/methods/aio/legal_regulatory.pyindex 7a17b07f2..6d27bd365 100644--- a/apps/python-sdk/firecrawl/v2/methods/aio/legal_regulatory.py+++ b/apps/python-sdk/firecrawl/v2/methods/aio/legal_regulatory.py@@ -24,4 +24,7 @@ async def legal_regulatory_search(response = await client.post(ENDPOINT, request.model_dump(exclude_none=True))if response.status_code != 200:handle_response_error(response, "search legal and regulatory sources")- return LegalRegulatorySearchResponse.model_validate(response.json())+ response_data = response.json()+ if not response_data.get("success"):+ handle_response_error(response, "search legal and regulatory sources")+ return LegalRegulatorySearchResponse.model_validate(response_data)diff --git a/apps/python-sdk/firecrawl/v2/methods/legal_regulatory.py b/apps/python-sdk/firecrawl/v2/methods/legal_regulatory.pyindex 36b967c3a..e168c1359 100644--- a/apps/python-sdk/firecrawl/v2/methods/legal_regulatory.py+++ b/apps/python-sdk/firecrawl/v2/methods/legal_regulatory.py@@ -23,4 +23,7 @@ def legal_regulatory_search(response = client.post(ENDPOINT, request.model_dump(exclude_none=True))if response.status_code != 200:handle_response_error(response, "search legal and regulatory sources")- return LegalRegulatorySearchResponse.model_validate(response.json())+ response_data = response.json()+ if not response_data.get("success"):+ handle_response_error(response, "search legal and regulatory sources")+ return LegalRegulatorySearchResponse.model_validate(response_data)