fix(js-sdk/crawl,batch-scrape): retry status call if it returns an error up to 3 times (#1343)

This commit is contained in:
Gergő Móricz 2025-03-15 12:42:53 +01:00 committed by GitHub
parent 905885abf9
commit ca93ba6c6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@mendable/firecrawl-js", "name": "@mendable/firecrawl-js",
"version": "1.19.1", "version": "1.19.2",
"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

@ -1332,12 +1332,14 @@ export default class FirecrawlApp {
checkInterval: number checkInterval: number
): Promise<CrawlStatusResponse | ErrorResponse> { ): Promise<CrawlStatusResponse | ErrorResponse> {
try { try {
let failedTries = 0;
while (true) { while (true) {
let statusResponse: AxiosResponse = await this.getRequest( let statusResponse: AxiosResponse = await this.getRequest(
`${this.apiUrl}/v1/crawl/${id}`, `${this.apiUrl}/v1/crawl/${id}`,
headers headers
); );
if (statusResponse.status === 200) { if (statusResponse.status === 200) {
failedTries = 0;
let statusData = statusResponse.data; let statusData = statusResponse.data;
if (statusData.status === "completed") { if (statusData.status === "completed") {
if ("data" in statusData) { if ("data" in statusData) {
@ -1369,9 +1371,12 @@ export default class FirecrawlApp {
); );
} }
} else { } else {
failedTries++;
if (failedTries >= 3) {
this.handleError(statusResponse, "check crawl status"); this.handleError(statusResponse, "check crawl status");
} }
} }
}
} catch (error: any) { } catch (error: any) {
throw new FirecrawlError(error, 500); throw new FirecrawlError(error, 500);
} }