[SDK] fixed none and undefined on response

This commit is contained in:
rafaelmmiller 2025-01-03 13:27:00 -03:00
parent ad49503f8a
commit bafcc008bc
4 changed files with 65 additions and 23 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@mendable/firecrawl-js",
"version": "1.11.0",
"version": "1.11.1",
"description": "JavaScript SDK for Firecrawl API",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@ -571,17 +571,30 @@ export default class FirecrawlApp {
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");
}
@ -805,17 +818,30 @@ export default class FirecrawlApp {
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");
}

View File

@ -13,7 +13,7 @@ import os
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")

View File

@ -266,17 +266,25 @@ class FirecrawlApp:
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')
@ -476,16 +484,24 @@ class FirecrawlApp:
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')