mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-14 12:35:54 +08:00
Nick: fix actions errors
This commit is contained in:
parent
20f89c3478
commit
1214d219e1
@ -96,6 +96,7 @@ export async function runWebScraper({
|
|||||||
...internalOptions,
|
...internalOptions,
|
||||||
});
|
});
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
|
error = response.error;
|
||||||
if (response.error instanceof Error) {
|
if (response.error instanceof Error) {
|
||||||
throw response.error;
|
throw response.error;
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,7 +3,7 @@ import * as Sentry from "@sentry/node";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { robustFetch } from "../../lib/fetch";
|
import { robustFetch } from "../../lib/fetch";
|
||||||
import { EngineError, SiteError } from "../../error";
|
import { ActionError, EngineError, SiteError } from "../../error";
|
||||||
|
|
||||||
const successSchema = z.object({
|
const successSchema = z.object({
|
||||||
jobId: z.string(),
|
jobId: z.string(),
|
||||||
@ -111,6 +111,12 @@ export async function fireEngineCheckStatus(
|
|||||||
status.error.includes("Chrome error: ")
|
status.error.includes("Chrome error: ")
|
||||||
) {
|
) {
|
||||||
throw new SiteError(status.error.split("Chrome error: ")[1]);
|
throw new SiteError(status.error.split("Chrome error: ")[1]);
|
||||||
|
} else if (
|
||||||
|
typeof status.error === "string" &&
|
||||||
|
// TODO: improve this later
|
||||||
|
status.error.includes("Element")
|
||||||
|
) {
|
||||||
|
throw new ActionError(status.error.split("Error: ")[1]);
|
||||||
} else {
|
} else {
|
||||||
throw new EngineError("Scrape job failed", {
|
throw new EngineError("Scrape job failed", {
|
||||||
cause: {
|
cause: {
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
FireEngineCheckStatusSuccess,
|
FireEngineCheckStatusSuccess,
|
||||||
StillProcessingError,
|
StillProcessingError,
|
||||||
} from "./checkStatus";
|
} from "./checkStatus";
|
||||||
import { EngineError, SiteError, TimeoutError } from "../../error";
|
import { ActionError, EngineError, SiteError, TimeoutError } from "../../error";
|
||||||
import * as Sentry from "@sentry/node";
|
import * as Sentry from "@sentry/node";
|
||||||
import { Action } from "../../../../lib/entities";
|
import { Action } from "../../../../lib/entities";
|
||||||
import { specialtyScrapeCheck } from "../utils/specialtyHandler";
|
import { specialtyScrapeCheck } from "../utils/specialtyHandler";
|
||||||
@ -68,7 +68,11 @@ async function performFireEngineScrape<
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof StillProcessingError) {
|
if (error instanceof StillProcessingError) {
|
||||||
// nop
|
// nop
|
||||||
} else if (error instanceof EngineError || error instanceof SiteError) {
|
} else if (
|
||||||
|
error instanceof EngineError ||
|
||||||
|
error instanceof SiteError ||
|
||||||
|
error instanceof ActionError
|
||||||
|
) {
|
||||||
logger.debug("Fire-engine scrape job failed.", {
|
logger.debug("Fire-engine scrape job failed.", {
|
||||||
error,
|
error,
|
||||||
jobId: scrape.jobId,
|
jobId: scrape.jobId,
|
||||||
|
@ -56,3 +56,13 @@ export class SiteError extends Error {
|
|||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ActionError extends Error {
|
||||||
|
public code: string;
|
||||||
|
constructor(code: string) {
|
||||||
|
super(
|
||||||
|
"Action(s) failed to complete. Error code: " + code,
|
||||||
|
);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
} from "./engines";
|
} from "./engines";
|
||||||
import { parseMarkdown } from "../../lib/html-to-markdown";
|
import { parseMarkdown } from "../../lib/html-to-markdown";
|
||||||
import {
|
import {
|
||||||
|
ActionError,
|
||||||
AddFeatureError,
|
AddFeatureError,
|
||||||
EngineError,
|
EngineError,
|
||||||
NoEnginesLeftError,
|
NoEnginesLeftError,
|
||||||
@ -288,6 +289,8 @@ async function scrapeURLLoop(meta: Meta): Promise<ScrapeUrlResponse> {
|
|||||||
throw error;
|
throw error;
|
||||||
} else if (error instanceof SiteError) {
|
} else if (error instanceof SiteError) {
|
||||||
throw error;
|
throw error;
|
||||||
|
} else if (error instanceof ActionError) {
|
||||||
|
throw error;
|
||||||
} else {
|
} else {
|
||||||
Sentry.captureException(error);
|
Sentry.captureException(error);
|
||||||
meta.logger.info(
|
meta.logger.info(
|
||||||
@ -408,6 +411,8 @@ export async function scrapeURL(
|
|||||||
// TODO: results?
|
// TODO: results?
|
||||||
} else if (error instanceof SiteError) {
|
} else if (error instanceof SiteError) {
|
||||||
meta.logger.warn("scrapeURL: Site failed to load in browser", { error });
|
meta.logger.warn("scrapeURL: Site failed to load in browser", { error });
|
||||||
|
} else if (error instanceof ActionError) {
|
||||||
|
meta.logger.warn("scrapeURL: Action(s) failed to complete", { error });
|
||||||
} else {
|
} else {
|
||||||
Sentry.captureException(error);
|
Sentry.captureException(error);
|
||||||
meta.logger.error("scrapeURL: Unexpected error happened", { error });
|
meta.logger.error("scrapeURL: Unexpected error happened", { error });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user