Skip to content

Commit 2bb6a4f

Browse files
committed
[MNY-332] Dashboard: Checkout link error message improvements (#8550)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e281ed1 commit 2bb6a4f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

apps/dashboard/src/@/actions/billing.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ export async function getChainInfraCheckoutURL(options: {
109109
}
110110

111111
const json = await res.json();
112+
113+
if (
114+
"error" in json &&
115+
"message" in json.error &&
116+
typeof json.error.message === "string"
117+
) {
118+
return {
119+
error: json.error.message,
120+
status: "error",
121+
} as const;
122+
}
123+
112124
if (!json.result) {
113125
return {
114126
error: "An unknown error occurred, please try again later.",

apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ export async function getBillingCheckoutUrl(options: {
7575
}
7676

7777
const json = await res.json();
78+
79+
if (
80+
"error" in json &&
81+
"message" in json.error &&
82+
typeof json.error.message === "string"
83+
) {
84+
return {
85+
error: json.error.message,
86+
status: "error",
87+
} as const;
88+
}
89+
7890
if (!json.result) {
7991
return {
8092
error: "An unknown error occurred, please try again later.",

0 commit comments

Comments
 (0)