From 576a6744a4ab78cadb11d6e8d8beed756b1ad5f6 Mon Sep 17 00:00:00 2001 From: bennykok Date: Wed, 31 Jan 2024 15:39:39 +0800 Subject: [PATCH] fix: safe catch stripe changed credential --- web/src/app/(app)/api/update-run/route.ts | 16 ++++++++++------ web/src/app/(app)/usage/page.tsx | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/web/src/app/(app)/api/update-run/route.ts b/web/src/app/(app)/api/update-run/route.ts index 8c7179d..f6fe276 100644 --- a/web/src/app/(app)/api/update-run/route.ts +++ b/web/src/app/(app)/api/update-run/route.ts @@ -108,12 +108,16 @@ export async function POST(request: Request) { durationInSec *= 4; break; } - await stripe.subscriptionItems.createUsageRecord( - sub.subscription_item_api_id, - { - quantity: durationInSec, - }, - ); + try { + await stripe.subscriptionItems.createUsageRecord( + sub.subscription_item_api_id, + { + quantity: durationInSec, + }, + ); + } catch (error) { + console.log(error); + } } } } diff --git a/web/src/app/(app)/usage/page.tsx b/web/src/app/(app)/usage/page.tsx index 9886f56..1db560c 100644 --- a/web/src/app/(app)/usage/page.tsx +++ b/web/src/app/(app)/usage/page.tsx @@ -16,11 +16,19 @@ const freeTierSeconds = 30000; export default async function Home() { const sub = await getCurrentPlanWithAuth(); - const data = sub?.subscription_item_api_id - ? await stripe.subscriptionItems.listUsageRecordSummaries( - sub?.subscription_item_api_id, - ) - : null; + let data: Awaited< + ReturnType + > | null = null; + + try { + data = sub?.subscription_item_api_id + ? await stripe.subscriptionItems.listUsageRecordSummaries( + sub?.subscription_item_api_id, + ) + : null; + } catch (e) { + console.error(e); + } return (