Nick: fix actions errors

This commit is contained in:
Nicolas 2024-12-15 15:43:12 -03:00
parent 20f89c3478
commit 1214d219e1
5 changed files with 29 additions and 3 deletions

View File

@ -96,6 +96,7 @@ export async function runWebScraper({
...internalOptions,
});
if (!response.success) {
error = response.error;
if (response.error instanceof Error) {
throw response.error;
} else {

View File

@ -3,7 +3,7 @@ import * as Sentry from "@sentry/node";
import { z } from "zod";
import { robustFetch } from "../../lib/fetch";
import { EngineError, SiteError } from "../../error";
import { ActionError, EngineError, SiteError } from "../../error";
const successSchema = z.object({
jobId: z.string(),
@ -111,6 +111,12 @@ export async function fireEngineCheckStatus(
status.error.includes("Chrome error: ")
) {
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 {
throw new EngineError("Scrape job failed", {
cause: {

View File

@ -13,7 +13,7 @@ import {
FireEngineCheckStatusSuccess,
StillProcessingError,
} from "./checkStatus";
import { EngineError, SiteError, TimeoutError } from "../../error";
import { ActionError, EngineError, SiteError, TimeoutError } from "../../error";
import * as Sentry from "@sentry/node";
import { Action } from "../../../../lib/entities";
import { specialtyScrapeCheck } from "../utils/specialtyHandler";
@ -68,7 +68,11 @@ async function performFireEngineScrape<
} catch (error) {
if (error instanceof StillProcessingError) {
// 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.", {
error,
jobId: scrape.jobId,

View File

@ -56,3 +56,13 @@ export class SiteError extends Error {
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;
}
}

View File

@ -12,6 +12,7 @@ import {
} from "./engines";
import { parseMarkdown } from "../../lib/html-to-markdown";
import {
ActionError,
AddFeatureError,
EngineError,
NoEnginesLeftError,
@ -288,6 +289,8 @@ async function scrapeURLLoop(meta: Meta): Promise<ScrapeUrlResponse> {
throw error;
} else if (error instanceof SiteError) {
throw error;
} else if (error instanceof ActionError) {
throw error;
} else {
Sentry.captureException(error);
meta.logger.info(
@ -408,6 +411,8 @@ export async function scrapeURL(
// TODO: results?
} else if (error instanceof SiteError) {
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 {
Sentry.captureException(error);
meta.logger.error("scrapeURL: Unexpected error happened", { error });