Skip to content

Commit 7b6381f

Browse files
committed
fix(webapp): correct apply wrapper return type for forward-compat with platform Result
1 parent 635c42a commit 7b6381f

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

apps/webapp/app/routes/admin.back-office.coupons.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,23 @@ export async function action({ request }: ActionFunctionArgs) {
165165
try {
166166
const result = await applyCouponDeal({ orgId, dealKey });
167167
if (!result.success) {
168+
// Cast to read `code` and `currentDealKey` from the wire body. The
169+
// platform's generic ErrorSchema currently strips these to `error`
170+
// only, so they arrive as undefined for now; the cast keeps the route
171+
// forward-compatible with a future schema loosening that preserves
172+
// them, at which point the precise UI messages will start rendering
173+
// automatically.
174+
const err = result as {
175+
success: false;
176+
error: string;
177+
code?: string;
178+
currentDealKey?: string;
179+
};
168180
return typedjson<ActionResponse>(
169181
{
170-
error: result.error ?? "Failed to apply coupon deal.",
171-
code: result.code,
172-
currentDealKey: result.currentDealKey ?? null,
182+
error: err.error,
183+
code: err.code,
184+
currentDealKey: err.currentDealKey ?? null,
173185
},
174186
{ status: 400 }
175187
);

apps/webapp/app/services/platform.v3.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
type UsageResult,
1818
type UsageSeriesParams,
1919
type CurrentPlan,
20-
type ApplyCouponDealResponse,
20+
type ApplyCouponDealResult,
2121
type CouponDiagnosticsResponse,
2222
type ListCouponDealsResponse,
2323
type ResolveCouponCustomerResponse,
@@ -844,7 +844,7 @@ export async function resolveCouponCustomer(
844844
export async function applyCouponDeal(input: {
845845
orgId: string;
846846
dealKey: string;
847-
}): Promise<ApplyCouponDealResponse> {
847+
}): Promise<ApplyCouponDealResult> {
848848
if (!client) throw new Error("Platform client not configured");
849849

850850
const [error, result] = await tryCatch(client.applyCouponDeal(input));

0 commit comments

Comments
 (0)