firecrawl 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +32 -20
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +30 -19
- package/package.json +1 -1
- package/src/index.ts +35 -19
- package/dump.rdb +0 -0
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
CrawlWatcher: () => CrawlWatcher,
|
|
34
|
+
FirecrawlError: () => FirecrawlError,
|
|
34
35
|
default: () => FirecrawlApp
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -38,6 +39,13 @@ var import_axios = __toESM(require("axios"), 1);
|
|
|
38
39
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
39
40
|
var import_isows = require("isows");
|
|
40
41
|
var import_typescript_event_target = require("typescript-event-target");
|
|
42
|
+
var FirecrawlError = class extends Error {
|
|
43
|
+
statusCode;
|
|
44
|
+
constructor(message, statusCode) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.statusCode = statusCode;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
41
49
|
var FirecrawlApp = class {
|
|
42
50
|
apiKey;
|
|
43
51
|
apiUrl;
|
|
@@ -47,7 +55,7 @@ var FirecrawlApp = class {
|
|
|
47
55
|
*/
|
|
48
56
|
constructor({ apiKey = null, apiUrl = null }) {
|
|
49
57
|
if (typeof apiKey !== "string") {
|
|
50
|
-
throw new
|
|
58
|
+
throw new FirecrawlError("No API key provided", 401);
|
|
51
59
|
}
|
|
52
60
|
this.apiKey = apiKey;
|
|
53
61
|
this.apiUrl = apiUrl || "https://api.firecrawl.dev";
|
|
@@ -94,13 +102,13 @@ var FirecrawlApp = class {
|
|
|
94
102
|
...responseData.data
|
|
95
103
|
};
|
|
96
104
|
} else {
|
|
97
|
-
throw new
|
|
105
|
+
throw new FirecrawlError(`Failed to scrape URL. Error: ${responseData.error}`, response.status);
|
|
98
106
|
}
|
|
99
107
|
} else {
|
|
100
108
|
this.handleError(response, "scrape URL");
|
|
101
109
|
}
|
|
102
110
|
} catch (error) {
|
|
103
|
-
throw new
|
|
111
|
+
throw new FirecrawlError(error.message, 500);
|
|
104
112
|
}
|
|
105
113
|
return { success: false, error: "Internal server error." };
|
|
106
114
|
}
|
|
@@ -111,7 +119,7 @@ var FirecrawlApp = class {
|
|
|
111
119
|
* @returns Throws an error advising to use version 0 of the API.
|
|
112
120
|
*/
|
|
113
121
|
async search(query, params) {
|
|
114
|
-
throw new
|
|
122
|
+
throw new FirecrawlError("Search is not supported in v1, please downgrade Firecrawl to 0.0.36.", 400);
|
|
115
123
|
}
|
|
116
124
|
/**
|
|
117
125
|
* Initiates a crawl job for a URL using the Firecrawl API.
|
|
@@ -138,9 +146,9 @@ var FirecrawlApp = class {
|
|
|
138
146
|
}
|
|
139
147
|
} catch (error) {
|
|
140
148
|
if (error.response?.data?.error) {
|
|
141
|
-
throw new
|
|
149
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
142
150
|
} else {
|
|
143
|
-
throw new
|
|
151
|
+
throw new FirecrawlError(error.message, 500);
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
154
|
return { success: false, error: "Internal server error." };
|
|
@@ -161,9 +169,9 @@ var FirecrawlApp = class {
|
|
|
161
169
|
}
|
|
162
170
|
} catch (error) {
|
|
163
171
|
if (error.response?.data?.error) {
|
|
164
|
-
throw new
|
|
172
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
165
173
|
} else {
|
|
166
|
-
throw new
|
|
174
|
+
throw new FirecrawlError(error.message, 500);
|
|
167
175
|
}
|
|
168
176
|
}
|
|
169
177
|
return { success: false, error: "Internal server error." };
|
|
@@ -176,7 +184,7 @@ var FirecrawlApp = class {
|
|
|
176
184
|
*/
|
|
177
185
|
async checkCrawlStatus(id, getAllData = false) {
|
|
178
186
|
if (!id) {
|
|
179
|
-
throw new
|
|
187
|
+
throw new FirecrawlError("No crawl ID provided", 400);
|
|
180
188
|
}
|
|
181
189
|
const headers = this.prepareHeaders();
|
|
182
190
|
try {
|
|
@@ -212,7 +220,7 @@ var FirecrawlApp = class {
|
|
|
212
220
|
this.handleError(response, "check crawl status");
|
|
213
221
|
}
|
|
214
222
|
} catch (error) {
|
|
215
|
-
throw new
|
|
223
|
+
throw new FirecrawlError(error.message, 500);
|
|
216
224
|
}
|
|
217
225
|
return { success: false, error: "Internal server error." };
|
|
218
226
|
}
|
|
@@ -222,7 +230,7 @@ var FirecrawlApp = class {
|
|
|
222
230
|
const id = crawl.id;
|
|
223
231
|
return new CrawlWatcher(id, this);
|
|
224
232
|
}
|
|
225
|
-
throw new
|
|
233
|
+
throw new FirecrawlError("Crawl job failed to start", 400);
|
|
226
234
|
}
|
|
227
235
|
async mapUrl(url, params) {
|
|
228
236
|
const headers = this.prepareHeaders();
|
|
@@ -239,7 +247,7 @@ var FirecrawlApp = class {
|
|
|
239
247
|
this.handleError(response, "map");
|
|
240
248
|
}
|
|
241
249
|
} catch (error) {
|
|
242
|
-
throw new
|
|
250
|
+
throw new FirecrawlError(error.message, 500);
|
|
243
251
|
}
|
|
244
252
|
return { success: false, error: "Internal server error." };
|
|
245
253
|
}
|
|
@@ -309,7 +317,7 @@ var FirecrawlApp = class {
|
|
|
309
317
|
statusData.data = data;
|
|
310
318
|
return statusData;
|
|
311
319
|
} else {
|
|
312
|
-
throw new
|
|
320
|
+
throw new FirecrawlError("Crawl job completed but no data was returned", 500);
|
|
313
321
|
}
|
|
314
322
|
} else if (["active", "paused", "pending", "queued", "waiting", "scraping"].includes(statusData.status)) {
|
|
315
323
|
checkInterval = Math.max(checkInterval, 2);
|
|
@@ -317,8 +325,9 @@ var FirecrawlApp = class {
|
|
|
317
325
|
(resolve) => setTimeout(resolve, checkInterval * 1e3)
|
|
318
326
|
);
|
|
319
327
|
} else {
|
|
320
|
-
throw new
|
|
321
|
-
`Crawl job failed or was stopped. Status: ${statusData.status}
|
|
328
|
+
throw new FirecrawlError(
|
|
329
|
+
`Crawl job failed or was stopped. Status: ${statusData.status}`,
|
|
330
|
+
500
|
|
322
331
|
);
|
|
323
332
|
}
|
|
324
333
|
} else {
|
|
@@ -334,12 +343,14 @@ var FirecrawlApp = class {
|
|
|
334
343
|
handleError(response, action) {
|
|
335
344
|
if ([402, 408, 409, 500].includes(response.status)) {
|
|
336
345
|
const errorMessage = response.data.error || "Unknown error occurred";
|
|
337
|
-
throw new
|
|
338
|
-
`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}
|
|
346
|
+
throw new FirecrawlError(
|
|
347
|
+
`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}`,
|
|
348
|
+
response.status
|
|
339
349
|
);
|
|
340
350
|
} else {
|
|
341
|
-
throw new
|
|
342
|
-
`Unexpected error occurred while trying to ${action}. Status code: ${response.status}
|
|
351
|
+
throw new FirecrawlError(
|
|
352
|
+
`Unexpected error occurred while trying to ${action}. Status code: ${response.status}`,
|
|
353
|
+
response.status
|
|
343
354
|
);
|
|
344
355
|
}
|
|
345
356
|
}
|
|
@@ -414,5 +425,6 @@ var CrawlWatcher = class extends import_typescript_event_target.TypedEventTarget
|
|
|
414
425
|
};
|
|
415
426
|
// Annotate the CommonJS export names for ESM import in node:
|
|
416
427
|
0 && (module.exports = {
|
|
417
|
-
CrawlWatcher
|
|
428
|
+
CrawlWatcher,
|
|
429
|
+
FirecrawlError
|
|
418
430
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -183,6 +183,14 @@ interface ErrorResponse {
|
|
|
183
183
|
success: false;
|
|
184
184
|
error: string;
|
|
185
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Custom error class for Firecrawl.
|
|
188
|
+
* Extends the built-in Error class to include a status code.
|
|
189
|
+
*/
|
|
190
|
+
declare class FirecrawlError extends Error {
|
|
191
|
+
statusCode: number;
|
|
192
|
+
constructor(message: string, statusCode: number);
|
|
193
|
+
}
|
|
186
194
|
/**
|
|
187
195
|
* Main class for interacting with the Firecrawl API.
|
|
188
196
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -285,4 +293,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
285
293
|
close(): void;
|
|
286
294
|
}
|
|
287
295
|
|
|
288
|
-
export { type Action, type ActionsResult, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };
|
|
296
|
+
export { type Action, type ActionsResult, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -183,6 +183,14 @@ interface ErrorResponse {
|
|
|
183
183
|
success: false;
|
|
184
184
|
error: string;
|
|
185
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Custom error class for Firecrawl.
|
|
188
|
+
* Extends the built-in Error class to include a status code.
|
|
189
|
+
*/
|
|
190
|
+
declare class FirecrawlError extends Error {
|
|
191
|
+
statusCode: number;
|
|
192
|
+
constructor(message: string, statusCode: number);
|
|
193
|
+
}
|
|
186
194
|
/**
|
|
187
195
|
* Main class for interacting with the Firecrawl API.
|
|
188
196
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -285,4 +293,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
285
293
|
close(): void;
|
|
286
294
|
}
|
|
287
295
|
|
|
288
|
-
export { type Action, type ActionsResult, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };
|
|
296
|
+
export { type Action, type ActionsResult, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, FirecrawlApp as default };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,13 @@ import axios, { AxiosError } from "axios";
|
|
|
3
3
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4
4
|
import { WebSocket } from "isows";
|
|
5
5
|
import { TypedEventTarget } from "typescript-event-target";
|
|
6
|
+
var FirecrawlError = class extends Error {
|
|
7
|
+
statusCode;
|
|
8
|
+
constructor(message, statusCode) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.statusCode = statusCode;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
6
13
|
var FirecrawlApp = class {
|
|
7
14
|
apiKey;
|
|
8
15
|
apiUrl;
|
|
@@ -12,7 +19,7 @@ var FirecrawlApp = class {
|
|
|
12
19
|
*/
|
|
13
20
|
constructor({ apiKey = null, apiUrl = null }) {
|
|
14
21
|
if (typeof apiKey !== "string") {
|
|
15
|
-
throw new
|
|
22
|
+
throw new FirecrawlError("No API key provided", 401);
|
|
16
23
|
}
|
|
17
24
|
this.apiKey = apiKey;
|
|
18
25
|
this.apiUrl = apiUrl || "https://api.firecrawl.dev";
|
|
@@ -59,13 +66,13 @@ var FirecrawlApp = class {
|
|
|
59
66
|
...responseData.data
|
|
60
67
|
};
|
|
61
68
|
} else {
|
|
62
|
-
throw new
|
|
69
|
+
throw new FirecrawlError(`Failed to scrape URL. Error: ${responseData.error}`, response.status);
|
|
63
70
|
}
|
|
64
71
|
} else {
|
|
65
72
|
this.handleError(response, "scrape URL");
|
|
66
73
|
}
|
|
67
74
|
} catch (error) {
|
|
68
|
-
throw new
|
|
75
|
+
throw new FirecrawlError(error.message, 500);
|
|
69
76
|
}
|
|
70
77
|
return { success: false, error: "Internal server error." };
|
|
71
78
|
}
|
|
@@ -76,7 +83,7 @@ var FirecrawlApp = class {
|
|
|
76
83
|
* @returns Throws an error advising to use version 0 of the API.
|
|
77
84
|
*/
|
|
78
85
|
async search(query, params) {
|
|
79
|
-
throw new
|
|
86
|
+
throw new FirecrawlError("Search is not supported in v1, please downgrade Firecrawl to 0.0.36.", 400);
|
|
80
87
|
}
|
|
81
88
|
/**
|
|
82
89
|
* Initiates a crawl job for a URL using the Firecrawl API.
|
|
@@ -103,9 +110,9 @@ var FirecrawlApp = class {
|
|
|
103
110
|
}
|
|
104
111
|
} catch (error) {
|
|
105
112
|
if (error.response?.data?.error) {
|
|
106
|
-
throw new
|
|
113
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
107
114
|
} else {
|
|
108
|
-
throw new
|
|
115
|
+
throw new FirecrawlError(error.message, 500);
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
118
|
return { success: false, error: "Internal server error." };
|
|
@@ -126,9 +133,9 @@ var FirecrawlApp = class {
|
|
|
126
133
|
}
|
|
127
134
|
} catch (error) {
|
|
128
135
|
if (error.response?.data?.error) {
|
|
129
|
-
throw new
|
|
136
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
130
137
|
} else {
|
|
131
|
-
throw new
|
|
138
|
+
throw new FirecrawlError(error.message, 500);
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
return { success: false, error: "Internal server error." };
|
|
@@ -141,7 +148,7 @@ var FirecrawlApp = class {
|
|
|
141
148
|
*/
|
|
142
149
|
async checkCrawlStatus(id, getAllData = false) {
|
|
143
150
|
if (!id) {
|
|
144
|
-
throw new
|
|
151
|
+
throw new FirecrawlError("No crawl ID provided", 400);
|
|
145
152
|
}
|
|
146
153
|
const headers = this.prepareHeaders();
|
|
147
154
|
try {
|
|
@@ -177,7 +184,7 @@ var FirecrawlApp = class {
|
|
|
177
184
|
this.handleError(response, "check crawl status");
|
|
178
185
|
}
|
|
179
186
|
} catch (error) {
|
|
180
|
-
throw new
|
|
187
|
+
throw new FirecrawlError(error.message, 500);
|
|
181
188
|
}
|
|
182
189
|
return { success: false, error: "Internal server error." };
|
|
183
190
|
}
|
|
@@ -187,7 +194,7 @@ var FirecrawlApp = class {
|
|
|
187
194
|
const id = crawl.id;
|
|
188
195
|
return new CrawlWatcher(id, this);
|
|
189
196
|
}
|
|
190
|
-
throw new
|
|
197
|
+
throw new FirecrawlError("Crawl job failed to start", 400);
|
|
191
198
|
}
|
|
192
199
|
async mapUrl(url, params) {
|
|
193
200
|
const headers = this.prepareHeaders();
|
|
@@ -204,7 +211,7 @@ var FirecrawlApp = class {
|
|
|
204
211
|
this.handleError(response, "map");
|
|
205
212
|
}
|
|
206
213
|
} catch (error) {
|
|
207
|
-
throw new
|
|
214
|
+
throw new FirecrawlError(error.message, 500);
|
|
208
215
|
}
|
|
209
216
|
return { success: false, error: "Internal server error." };
|
|
210
217
|
}
|
|
@@ -274,7 +281,7 @@ var FirecrawlApp = class {
|
|
|
274
281
|
statusData.data = data;
|
|
275
282
|
return statusData;
|
|
276
283
|
} else {
|
|
277
|
-
throw new
|
|
284
|
+
throw new FirecrawlError("Crawl job completed but no data was returned", 500);
|
|
278
285
|
}
|
|
279
286
|
} else if (["active", "paused", "pending", "queued", "waiting", "scraping"].includes(statusData.status)) {
|
|
280
287
|
checkInterval = Math.max(checkInterval, 2);
|
|
@@ -282,8 +289,9 @@ var FirecrawlApp = class {
|
|
|
282
289
|
(resolve) => setTimeout(resolve, checkInterval * 1e3)
|
|
283
290
|
);
|
|
284
291
|
} else {
|
|
285
|
-
throw new
|
|
286
|
-
`Crawl job failed or was stopped. Status: ${statusData.status}
|
|
292
|
+
throw new FirecrawlError(
|
|
293
|
+
`Crawl job failed or was stopped. Status: ${statusData.status}`,
|
|
294
|
+
500
|
|
287
295
|
);
|
|
288
296
|
}
|
|
289
297
|
} else {
|
|
@@ -299,12 +307,14 @@ var FirecrawlApp = class {
|
|
|
299
307
|
handleError(response, action) {
|
|
300
308
|
if ([402, 408, 409, 500].includes(response.status)) {
|
|
301
309
|
const errorMessage = response.data.error || "Unknown error occurred";
|
|
302
|
-
throw new
|
|
303
|
-
`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}
|
|
310
|
+
throw new FirecrawlError(
|
|
311
|
+
`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}`,
|
|
312
|
+
response.status
|
|
304
313
|
);
|
|
305
314
|
} else {
|
|
306
|
-
throw new
|
|
307
|
-
`Unexpected error occurred while trying to ${action}. Status code: ${response.status}
|
|
315
|
+
throw new FirecrawlError(
|
|
316
|
+
`Unexpected error occurred while trying to ${action}. Status code: ${response.status}`,
|
|
317
|
+
response.status
|
|
308
318
|
);
|
|
309
319
|
}
|
|
310
320
|
}
|
|
@@ -379,5 +389,6 @@ var CrawlWatcher = class extends TypedEventTarget {
|
|
|
379
389
|
};
|
|
380
390
|
export {
|
|
381
391
|
CrawlWatcher,
|
|
392
|
+
FirecrawlError,
|
|
382
393
|
FirecrawlApp as default
|
|
383
394
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -199,6 +199,19 @@ export interface ErrorResponse {
|
|
|
199
199
|
error: string;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Custom error class for Firecrawl.
|
|
205
|
+
* Extends the built-in Error class to include a status code.
|
|
206
|
+
*/
|
|
207
|
+
export class FirecrawlError extends Error {
|
|
208
|
+
statusCode: number;
|
|
209
|
+
constructor(message: string, statusCode: number) {
|
|
210
|
+
super(message);
|
|
211
|
+
this.statusCode = statusCode;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
202
215
|
/**
|
|
203
216
|
* Main class for interacting with the Firecrawl API.
|
|
204
217
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -213,7 +226,7 @@ export default class FirecrawlApp {
|
|
|
213
226
|
*/
|
|
214
227
|
constructor({ apiKey = null, apiUrl = null }: FirecrawlAppConfig) {
|
|
215
228
|
if (typeof apiKey !== "string") {
|
|
216
|
-
throw new
|
|
229
|
+
throw new FirecrawlError("No API key provided", 401);
|
|
217
230
|
}
|
|
218
231
|
|
|
219
232
|
this.apiKey = apiKey;
|
|
@@ -268,13 +281,13 @@ export default class FirecrawlApp {
|
|
|
268
281
|
...responseData.data
|
|
269
282
|
};
|
|
270
283
|
} else {
|
|
271
|
-
throw new
|
|
284
|
+
throw new FirecrawlError(`Failed to scrape URL. Error: ${responseData.error}`, response.status);
|
|
272
285
|
}
|
|
273
286
|
} else {
|
|
274
287
|
this.handleError(response, "scrape URL");
|
|
275
288
|
}
|
|
276
289
|
} catch (error: any) {
|
|
277
|
-
throw new
|
|
290
|
+
throw new FirecrawlError(error.message, 500);
|
|
278
291
|
}
|
|
279
292
|
return { success: false, error: "Internal server error." };
|
|
280
293
|
}
|
|
@@ -289,7 +302,7 @@ export default class FirecrawlApp {
|
|
|
289
302
|
query: string,
|
|
290
303
|
params?: any
|
|
291
304
|
): Promise<any> {
|
|
292
|
-
throw new
|
|
305
|
+
throw new FirecrawlError("Search is not supported in v1, please downgrade Firecrawl to 0.0.36.", 400);
|
|
293
306
|
}
|
|
294
307
|
|
|
295
308
|
/**
|
|
@@ -322,9 +335,9 @@ export default class FirecrawlApp {
|
|
|
322
335
|
}
|
|
323
336
|
} catch (error: any) {
|
|
324
337
|
if (error.response?.data?.error) {
|
|
325
|
-
throw new
|
|
338
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ''}`, error.response.status);
|
|
326
339
|
} else {
|
|
327
|
-
throw new
|
|
340
|
+
throw new FirecrawlError(error.message, 500);
|
|
328
341
|
}
|
|
329
342
|
}
|
|
330
343
|
return { success: false, error: "Internal server error." };
|
|
@@ -350,9 +363,9 @@ export default class FirecrawlApp {
|
|
|
350
363
|
}
|
|
351
364
|
} catch (error: any) {
|
|
352
365
|
if (error.response?.data?.error) {
|
|
353
|
-
throw new
|
|
366
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ''}`, error.response.status);
|
|
354
367
|
} else {
|
|
355
|
-
throw new
|
|
368
|
+
throw new FirecrawlError(error.message, 500);
|
|
356
369
|
}
|
|
357
370
|
}
|
|
358
371
|
return { success: false, error: "Internal server error." };
|
|
@@ -366,7 +379,7 @@ export default class FirecrawlApp {
|
|
|
366
379
|
*/
|
|
367
380
|
async checkCrawlStatus(id?: string, getAllData = false): Promise<CrawlStatusResponse | ErrorResponse> {
|
|
368
381
|
if (!id) {
|
|
369
|
-
throw new
|
|
382
|
+
throw new FirecrawlError("No crawl ID provided", 400);
|
|
370
383
|
}
|
|
371
384
|
|
|
372
385
|
const headers: AxiosRequestHeaders = this.prepareHeaders();
|
|
@@ -403,7 +416,7 @@ export default class FirecrawlApp {
|
|
|
403
416
|
this.handleError(response, "check crawl status");
|
|
404
417
|
}
|
|
405
418
|
} catch (error: any) {
|
|
406
|
-
throw new
|
|
419
|
+
throw new FirecrawlError(error.message, 500);
|
|
407
420
|
}
|
|
408
421
|
return { success: false, error: "Internal server error." };
|
|
409
422
|
}
|
|
@@ -420,7 +433,7 @@ export default class FirecrawlApp {
|
|
|
420
433
|
return new CrawlWatcher(id, this);
|
|
421
434
|
}
|
|
422
435
|
|
|
423
|
-
throw new
|
|
436
|
+
throw new FirecrawlError("Crawl job failed to start", 400);
|
|
424
437
|
}
|
|
425
438
|
|
|
426
439
|
async mapUrl(url: string, params?: MapParams): Promise<MapResponse | ErrorResponse> {
|
|
@@ -439,7 +452,7 @@ export default class FirecrawlApp {
|
|
|
439
452
|
this.handleError(response, "map");
|
|
440
453
|
}
|
|
441
454
|
} catch (error: any) {
|
|
442
|
-
throw new
|
|
455
|
+
throw new FirecrawlError(error.message, 500);
|
|
443
456
|
}
|
|
444
457
|
return { success: false, error: "Internal server error." };
|
|
445
458
|
}
|
|
@@ -524,7 +537,7 @@ export default class FirecrawlApp {
|
|
|
524
537
|
statusData.data = data;
|
|
525
538
|
return statusData;
|
|
526
539
|
} else {
|
|
527
|
-
throw new
|
|
540
|
+
throw new FirecrawlError("Crawl job completed but no data was returned", 500);
|
|
528
541
|
}
|
|
529
542
|
} else if (
|
|
530
543
|
["active", "paused", "pending", "queued", "waiting", "scraping"].includes(statusData.status)
|
|
@@ -534,8 +547,9 @@ export default class FirecrawlApp {
|
|
|
534
547
|
setTimeout(resolve, checkInterval * 1000)
|
|
535
548
|
);
|
|
536
549
|
} else {
|
|
537
|
-
throw new
|
|
538
|
-
`Crawl job failed or was stopped. Status: ${statusData.status}
|
|
550
|
+
throw new FirecrawlError(
|
|
551
|
+
`Crawl job failed or was stopped. Status: ${statusData.status}`,
|
|
552
|
+
500
|
|
539
553
|
);
|
|
540
554
|
}
|
|
541
555
|
} else {
|
|
@@ -553,12 +567,14 @@ export default class FirecrawlApp {
|
|
|
553
567
|
if ([402, 408, 409, 500].includes(response.status)) {
|
|
554
568
|
const errorMessage: string =
|
|
555
569
|
response.data.error || "Unknown error occurred";
|
|
556
|
-
throw new
|
|
557
|
-
`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}
|
|
570
|
+
throw new FirecrawlError(
|
|
571
|
+
`Failed to ${action}. Status code: ${response.status}. Error: ${errorMessage}`,
|
|
572
|
+
response.status
|
|
558
573
|
);
|
|
559
574
|
} else {
|
|
560
|
-
throw new
|
|
561
|
-
`Unexpected error occurred while trying to ${action}. Status code: ${response.status}
|
|
575
|
+
throw new FirecrawlError(
|
|
576
|
+
`Unexpected error occurred while trying to ${action}. Status code: ${response.status}`,
|
|
577
|
+
response.status
|
|
562
578
|
);
|
|
563
579
|
}
|
|
564
580
|
}
|
package/dump.rdb
DELETED
|
Binary file
|