Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Nick: update extract in case there is an error

Nicolas11af214db163
diff --git a/apps/api/src/controllers/v1/extract-status.ts b/apps/api/src/controllers/v1/extract-status.ts
index a42f17fae..ce58a3429 100644
--- a/apps/api/src/controllers/v1/extract-status.ts
+++ b/apps/api/src/controllers/v1/extract-status.ts
@@ -34,6 +34,7 @@ export async function extractStatusController(
success: true,
data: data,
status: extract.status,
+ error: extract?.error ?? undefined,
expiresAt: (await getExtractExpiry(req.params.jobId)).toISOString(),
});
}
diff --git a/apps/api/src/lib/extract/extract-redis.ts b/apps/api/src/lib/extract/extract-redis.ts
index 2d9410f92..f4ed03692 100644
--- a/apps/api/src/lib/extract/extract-redis.ts
+++ b/apps/api/src/lib/extract/extract-redis.ts
@@ -7,6 +7,7 @@ export type StoredExtract = {
plan?: string;
createdAt: number;
status: "processing" | "completed" | "failed" | "cancelled";
+ error?: any;
};
export async function saveExtract(id: string, extract: StoredExtract) {
diff --git a/apps/api/src/services/queue-worker.ts b/apps/api/src/services/queue-worker.ts
index 96fad2d2e..180bef108 100644
--- a/apps/api/src/services/queue-worker.ts
+++ b/apps/api/src/services/queue-worker.ts
@@ -55,6 +55,7 @@ import { Document } from "../controllers/v1/types";
import { performExtraction } from "../lib/extract/extraction-service";
import { supabase_service } from "../services/supabase";
import { normalizeUrl, normalizeUrlOnlyHostname } from "../lib/canonical-url";
+import { saveExtract, updateExtract } from "../lib/extract/extract-redis";
configDotenv();
@@ -351,6 +352,11 @@ const processExtractJobInternal = async (token: string, job: Job & { id: string
// Move job to failed state in Redis
await job.moveToFailed(error, token, false);
+
+ await updateExtract(job.data.extractId, {
+ status: "failed",
+ error: error.error ?? error ?? "Unknown error, please contact [email protected]. Extract id: " + job.data.extractId,
+ });
// throw error;
} finally {