Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] fixed none and undefined on response #1034

Merged
merged 6 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/js-sdk/firecrawl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mendable/firecrawl-js",
"version": "1.11.2",
"version": "1.11.3",
"description": "JavaScript SDK for Firecrawl API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
55 changes: 45 additions & 10 deletions apps/js-sdk/firecrawl/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,23 +565,39 @@ export default class FirecrawlApp {
if ("data" in statusData) {
let data = statusData.data;
while (typeof statusData === 'object' && 'next' in statusData) {
if (data.length === 0) {
break
}
statusData = (await this.getRequest(statusData.next, headers)).data;
data = data.concat(statusData.data);
}
allData = data;
}
}
return ({

let resp: CrawlStatusResponse | ErrorResponse = {
success: response.data.success,
status: response.data.status,
total: response.data.total,
completed: response.data.completed,
creditsUsed: response.data.creditsUsed,
expiresAt: new Date(response.data.expiresAt),
next: response.data.next,
data: allData,
error: response.data.error,
})
data: allData
}

if (!response.data.success && response.data.error) {
resp = {
...resp,
success: false,
error: response.data.error
} as ErrorResponse;
}

if (response.data.next) {
(resp as CrawlStatusResponse).next = response.data.next;
}

return resp;
} else {
this.handleError(response, "check crawl status");
}
Expand Down Expand Up @@ -799,23 +815,39 @@ export default class FirecrawlApp {
if ("data" in statusData) {
let data = statusData.data;
while (typeof statusData === 'object' && 'next' in statusData) {
if (data.length === 0) {
break
}
statusData = (await this.getRequest(statusData.next, headers)).data;
data = data.concat(statusData.data);
}
allData = data;
}
}
return ({

let resp: BatchScrapeStatusResponse | ErrorResponse = {
success: response.data.success,
status: response.data.status,
total: response.data.total,
completed: response.data.completed,
creditsUsed: response.data.creditsUsed,
expiresAt: new Date(response.data.expiresAt),
next: response.data.next,
data: allData,
error: response.data.error,
})
data: allData
}

if (!response.data.success && response.data.error) {
resp = {
...resp,
success: false,
error: response.data.error
} as ErrorResponse;
}

if (response.data.next) {
(resp as BatchScrapeStatusResponse).next = response.data.next;
}

return resp;
} else {
this.handleError(response, "check batch scrape status");
}
Expand Down Expand Up @@ -971,6 +1003,9 @@ export default class FirecrawlApp {
if ("data" in statusData) {
let data = statusData.data;
while (typeof statusData === 'object' && 'next' in statusData) {
if (data.length === 0) {
break
}
statusResponse = await this.getRequest(statusData.next, headers);
statusData = statusResponse.data;
data = data.concat(statusData.data);
Expand Down
2 changes: 1 addition & 1 deletion apps/python-sdk/firecrawl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .firecrawl import FirecrawlApp # noqa

__version__ = "1.8.0"
__version__ = "1.8.1"

# Define the logger for the Firecrawl project
logger: logging.Logger = logging.getLogger("firecrawl")
Expand Down
44 changes: 33 additions & 11 deletions apps/python-sdk/firecrawl/firecrawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def check_crawl_status(self, id: str) -> Any:
if 'data' in status_data:
data = status_data['data']
while 'next' in status_data:
if len(status_data['data']) == 0:
break
next_url = status_data.get('next')
if not next_url:
logger.warning("Expected 'next' URL is missing.")
Expand All @@ -266,17 +268,25 @@ def check_crawl_status(self, id: str) -> Any:
logger.error(f"Error during pagination request: {e}")
break
status_data['data'] = data

return {
'success': True,

response = {
'status': status_data.get('status'),
'total': status_data.get('total'),
'completed': status_data.get('completed'),
'creditsUsed': status_data.get('creditsUsed'),
'expiresAt': status_data.get('expiresAt'),
'data': status_data.get('data'),
'error': status_data.get('error'),
'next': status_data.get('next', None)
'data': status_data.get('data')
}

if 'error' in status_data:
response['error'] = status_data['error']

if 'next' in status_data:
response['next'] = status_data['next']

return {
'success': False if 'error' in status_data else True,
**response
}
else:
self._handle_error(response, 'check crawl status')
Expand Down Expand Up @@ -459,6 +469,8 @@ def check_batch_scrape_status(self, id: str) -> Any:
if 'data' in status_data:
data = status_data['data']
while 'next' in status_data:
if len(status_data['data']) == 0:
break
next_url = status_data.get('next')
if not next_url:
logger.warning("Expected 'next' URL is missing.")
Expand All @@ -476,16 +488,24 @@ def check_batch_scrape_status(self, id: str) -> Any:
break
status_data['data'] = data

return {
'success': True,
response = {
'status': status_data.get('status'),
'total': status_data.get('total'),
'completed': status_data.get('completed'),
'creditsUsed': status_data.get('creditsUsed'),
'expiresAt': status_data.get('expiresAt'),
'data': status_data.get('data'),
'error': status_data.get('error'),
'next': status_data.get('next', None)
'data': status_data.get('data')
}

if 'error' in status_data:
response['error'] = status_data['error']

if 'next' in status_data:
response['next'] = status_data['next']

return {
'success': False if 'error' in status_data else True,
**response
}
else:
self._handle_error(response, 'check batch scrape status')
Expand Down Expand Up @@ -669,6 +689,8 @@ def _monitor_job_status(self, id: str, headers: Dict[str, str], poll_interval: i
if 'data' in status_data:
data = status_data['data']
while 'next' in status_data:
if len(status_data['data']) == 0:
break
status_response = self._get_request(status_data['next'], headers)
status_data = status_response.json()
data.extend(status_data.get('data', []))
Expand Down
Loading