[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", "name": "@mendable/firecrawl-js",
"version": "1.11.0", "version": "1.11.1",
"description": "JavaScript SDK for Firecrawl API", "description": "JavaScript SDK for Firecrawl API",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -571,17 +571,30 @@ export default class FirecrawlApp {
allData = data; allData = data;
} }
} }
return ({
let resp: CrawlStatusResponse | ErrorResponse = {
success: response.data.success, success: response.data.success,
status: response.data.status, status: response.data.status,
total: response.data.total, total: response.data.total,
completed: response.data.completed, completed: response.data.completed,
creditsUsed: response.data.creditsUsed, creditsUsed: response.data.creditsUsed,
expiresAt: new Date(response.data.expiresAt), expiresAt: new Date(response.data.expiresAt),
next: response.data.next, data: allData
data: allData, }
error: response.data.error,
}) 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 { } else {
this.handleError(response, "check crawl status"); this.handleError(response, "check crawl status");
} }
@ -805,17 +818,30 @@ export default class FirecrawlApp {
allData = data; allData = data;
} }
} }
return ({
let resp: BatchScrapeStatusResponse | ErrorResponse = {
success: response.data.success, success: response.data.success,
status: response.data.status, status: response.data.status,
total: response.data.total, total: response.data.total,
completed: response.data.completed, completed: response.data.completed,
creditsUsed: response.data.creditsUsed, creditsUsed: response.data.creditsUsed,
expiresAt: new Date(response.data.expiresAt), expiresAt: new Date(response.data.expiresAt),
next: response.data.next, data: allData
data: allData, }
error: response.data.error,
}) 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 { } else {
this.handleError(response, "check batch scrape status"); this.handleError(response, "check batch scrape status");
} }

View File

@ -13,7 +13,7 @@ import os
from .firecrawl import FirecrawlApp # noqa from .firecrawl import FirecrawlApp # noqa
__version__ = "1.8.0" __version__ = "1.8.1"
# Define the logger for the Firecrawl project # Define the logger for the Firecrawl project
logger: logging.Logger = logging.getLogger("firecrawl") logger: logging.Logger = logging.getLogger("firecrawl")

View File

@ -266,17 +266,25 @@ class FirecrawlApp:
logger.error(f"Error during pagination request: {e}") logger.error(f"Error during pagination request: {e}")
break break
status_data['data'] = data status_data['data'] = data
return { response = {
'success': True,
'status': status_data.get('status'), 'status': status_data.get('status'),
'total': status_data.get('total'), 'total': status_data.get('total'),
'completed': status_data.get('completed'), 'completed': status_data.get('completed'),
'creditsUsed': status_data.get('creditsUsed'), 'creditsUsed': status_data.get('creditsUsed'),
'expiresAt': status_data.get('expiresAt'), 'expiresAt': status_data.get('expiresAt'),
'data': status_data.get('data'), 'data': status_data.get('data')
'error': status_data.get('error'), }
'next': status_data.get('next', None)
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: else:
self._handle_error(response, 'check crawl status') self._handle_error(response, 'check crawl status')
@ -476,16 +484,24 @@ class FirecrawlApp:
break break
status_data['data'] = data status_data['data'] = data
return { response = {
'success': True,
'status': status_data.get('status'), 'status': status_data.get('status'),
'total': status_data.get('total'), 'total': status_data.get('total'),
'completed': status_data.get('completed'), 'completed': status_data.get('completed'),
'creditsUsed': status_data.get('creditsUsed'), 'creditsUsed': status_data.get('creditsUsed'),
'expiresAt': status_data.get('expiresAt'), 'expiresAt': status_data.get('expiresAt'),
'data': status_data.get('data'), 'data': status_data.get('data')
'error': status_data.get('error'), }
'next': status_data.get('next', None)
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: else:
self._handle_error(response, 'check batch scrape status') self._handle_error(response, 'check batch scrape status')