diff --git a/apps/api/src/controllers/v0/scrape.ts b/apps/api/src/controllers/v0/scrape.ts index 40df5021..bc91da18 100644 --- a/apps/api/src/controllers/v0/scrape.ts +++ b/apps/api/src/controllers/v0/scrape.ts @@ -244,14 +244,10 @@ export async function scrapeController(req: Request, res: Response) { } if (creditsToBeBilled > 0) { // billing for doc done on queue end, bill only for llm extraction - const billingResult = await billTeam(team_id, creditsToBeBilled); - if (!billingResult.success) { - return res.status(402).json({ - success: false, - error: - "Failed to bill team. Insufficient credits or subscription not found.", - }); - } + billTeam(team_id, creditsToBeBilled).catch(error => { + Logger.error(`Failed to bill team ${team_id} for ${creditsToBeBilled} credits: ${error}`); + // Optionally, you could notify an admin or add to a retry queue here + }); } } diff --git a/apps/api/src/controllers/v0/search.ts b/apps/api/src/controllers/v0/search.ts index 825abbe1..5ef2b767 100644 --- a/apps/api/src/controllers/v0/search.ts +++ b/apps/api/src/controllers/v0/search.ts @@ -54,18 +54,10 @@ export async function searchHelper( if (justSearch) { - const billingResult = await billTeam( - team_id, - res.length - ); - if (!billingResult.success) { - return { - success: false, - error: - "Failed to bill team. Insufficient credits or subscription not found.", - returnCode: 402, - }; - } + billTeam(team_id, res.length).catch(error => { + Logger.error(`Failed to bill team ${team_id} for ${res.length} credits: ${error}`); + // Optionally, you could notify an admin or add to a retry queue here + }); return { success: true, data: res, returnCode: 200 }; } diff --git a/apps/api/src/controllers/v1/map.ts b/apps/api/src/controllers/v1/map.ts index 21e91840..4c94f041 100644 --- a/apps/api/src/controllers/v1/map.ts +++ b/apps/api/src/controllers/v1/map.ts @@ -18,6 +18,7 @@ import { fireEngineMap } from "../../search/fireEngine"; import { billTeam } from "../../services/billing/credit_billing"; import { logJob } from "../../services/logging/log_job"; import { performCosineSimilarity } from "../../lib/map-cosine"; +import { Logger } from "../../lib/logger"; configDotenv(); @@ -100,7 +101,10 @@ export async function mapController( // remove duplicates that could be due to http/https or www links = removeDuplicateUrls(links); - await billTeam(req.auth.team_id, 1); + billTeam(req.auth.team_id, 1).catch(error => { + Logger.error(`Failed to bill team ${req.auth.team_id} for 1 credit: ${error}`); + // Optionally, you could notify an admin or add to a retry queue here + }); const endTime = new Date().getTime(); const timeTakenInSeconds = (endTime - startTime) / 1000; diff --git a/apps/api/src/controllers/v1/scrape.ts b/apps/api/src/controllers/v1/scrape.ts index 9fba1a45..0835cc2a 100644 --- a/apps/api/src/controllers/v1/scrape.ts +++ b/apps/api/src/controllers/v1/scrape.ts @@ -106,14 +106,10 @@ export async function scrapeController( creditsToBeBilled = 50; } - const billingResult = await billTeam(req.auth.team_id, creditsToBeBilled); - if (!billingResult.success) { - return res.status(402).json({ - success: false, - error: - "Failed to bill team. Insufficient credits or subscription not found.", - }); - } + billTeam(req.auth.team_id, creditsToBeBilled).catch(error => { + Logger.error(`Failed to bill team ${req.auth.team_id} for ${creditsToBeBilled} credits: ${error}`); + // Optionally, you could notify an admin or add to a retry queue here + }); if (!pageOptions || !pageOptions.includeRawHtml) { if (doc && doc.rawHtml) { diff --git a/apps/api/src/main/runWebScraper.ts b/apps/api/src/main/runWebScraper.ts index 2268f9ed..cd199fa1 100644 --- a/apps/api/src/main/runWebScraper.ts +++ b/apps/api/src/main/runWebScraper.ts @@ -118,15 +118,10 @@ export async function runWebScraper({ : docs; if(is_scrape === false) { - const billingResult = await billTeam(team_id, filteredDocs.length); - if (!billingResult.success) { - // throw new Error("Failed to bill team, no subscription was found"); - return { - success: false, - message: "Failed to bill team, no subscription was found", - docs: [], - }; - } + billTeam(team_id, filteredDocs.length).catch(error => { + Logger.error(`Failed to bill team ${team_id} for ${filteredDocs.length} credits: ${error}`); + // Optionally, you could notify an admin or add to a retry queue here + }); } diff --git a/apps/api/src/services/billing/credit_billing.ts b/apps/api/src/services/billing/credit_billing.ts index 2cfea85a..ab00eab9 100644 --- a/apps/api/src/services/billing/credit_billing.ts +++ b/apps/api/src/services/billing/credit_billing.ts @@ -465,8 +465,8 @@ async function createCreditUsage({ subscription_id?: string; credits: number; }) { - const { data: credit_usage } = await supabase_service - .from("credit_usage") + await supabase_service + .from("credit_usage") .insert([ { team_id, @@ -474,8 +474,7 @@ async function createCreditUsage({ subscription_id: subscription_id || null, created_at: new Date(), }, - ]) - .select(); + ]); - return { success: true, credit_usage }; + return { success: true }; }