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",
"version": "1.19.1",
"version": "1.19.2",
"description": "JavaScript SDK for Firecrawl API",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

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