From 2bb6a4f9a39e4d4def3e4ee7a334156fcad70d58 Mon Sep 17 00:00:00 2001 From: MananTank Date: Fri, 12 Dec 2025 17:56:56 +0000 Subject: [PATCH] [MNY-332] Dashboard: Checkout link error message improvements (#8550) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR enhances error handling in the `billing.ts` files by checking for a specific error structure in the JSON response. If the error is present and formatted correctly, it returns a detailed error message instead of a generic one. ### Detailed summary - Added error handling for JSON responses in `apps/dashboard/src/@/actions/billing.ts`: - Checks if `error` and `message` exist in the response. - Validates that `json.error.message` is a string. - Returns a structured error object with the message and status. - Similar changes were made in `apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit ## Bug Fixes * Improved error message handling for billing operations to display API-provided error messages to users instead of generic fallback errors, enabling clearer feedback when checkout transactions encounter issues. ✏️ Tip: You can customize this high-level summary in your review settings. --- apps/dashboard/src/@/actions/billing.ts | 12 ++++++++++++ .../src/app/(app)/(stripe)/utils/billing.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/apps/dashboard/src/@/actions/billing.ts b/apps/dashboard/src/@/actions/billing.ts index 1abca004b60..1eb0a9b78ba 100644 --- a/apps/dashboard/src/@/actions/billing.ts +++ b/apps/dashboard/src/@/actions/billing.ts @@ -109,6 +109,18 @@ export async function getChainInfraCheckoutURL(options: { } const json = await res.json(); + + if ( + "error" in json && + "message" in json.error && + typeof json.error.message === "string" + ) { + return { + error: json.error.message, + status: "error", + } as const; + } + if (!json.result) { return { error: "An unknown error occurred, please try again later.", diff --git a/apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts b/apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts index 16af4bc82f8..302838ce41e 100644 --- a/apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts +++ b/apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts @@ -75,6 +75,18 @@ export async function getBillingCheckoutUrl(options: { } const json = await res.json(); + + if ( + "error" in json && + "message" in json.error && + typeof json.error.message === "string" + ) { + return { + error: json.error.message, + status: "error", + } as const; + } + if (!json.result) { return { error: "An unknown error occurred, please try again later.",