Skip to content

Commit 2b95f4c

Browse files
committed
fix(webapp): address review feedback on promo credits
- getPromoCredits returns undefined (not null) on failure so SWR does not cache a transient error as "no credits" for the stale TTL - setPlan always returns a Response (no implicit undefined fall-through) - prefix unused catch bindings with _ to satisfy no-unused-vars - drop unused billing-limit schema imports - clarify the changelog wording (redeemed at plan selection)
1 parent 74c160e commit 2b95f4c

2 files changed

Lines changed: 31 additions & 24 deletions

File tree

.server-changes/promo-credits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ area: webapp
33
type: feature
44
---
55

6-
Promo credits: a /promo signup landing page, applying a promo code when an org is created, and showing remaining credits on the usage page.
6+
Promo credits: a /promo signup landing page, redeeming a promo code when a new org selects a plan, and showing remaining credits on the usage page.

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

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import {
2222
BillingLimitsActiveResultSchema,
2323
BillingLimitsPendingResolvesResultSchema,
2424
EntitlementResultSchema,
25-
ResolveBillingLimitRequestSchema,
26-
UpdateBillingLimitRequestSchema,
2725
asPlatformSchema,
2826
type BillingLimitResult,
2927
type BillingLimitsActiveResult,
@@ -352,7 +350,7 @@ export async function getCurrentPlan(orgId: string) {
352350
};
353351

354352
return { ...result, usage };
355-
} catch (e) {
353+
} catch (_e) {
356354
recordPlatformFailure("getCurrentPlan", "caught");
357355
return undefined;
358356
}
@@ -393,7 +391,7 @@ export async function getLimits(orgId: string) {
393391
}
394392

395393
return result.v3Subscription?.plan?.limits;
396-
} catch (e) {
394+
} catch (_e) {
397395
recordPlatformFailure("getLimits", "caught");
398396
return undefined;
399397
}
@@ -469,7 +467,7 @@ export async function customerPortalUrl(orgId: string, orgSlug: string) {
469467
return client.createPortalSession(orgId, {
470468
returnUrl: `${env.APP_ORIGIN}${organizationBillingPath({ slug: orgSlug })}`,
471469
});
472-
} catch (e) {
470+
} catch (_e) {
473471
recordPlatformFailure("customerPortalUrl", "caught");
474472
return undefined;
475473
}
@@ -485,7 +483,7 @@ export async function getPlans() {
485483
return undefined;
486484
}
487485
return result;
488-
} catch (e) {
486+
} catch (_e) {
489487
recordPlatformFailure("getPlans", "caught");
490488
return undefined;
491489
}
@@ -544,6 +542,12 @@ export async function setPlan(
544542
return redirectWithSuccessMessage(callerPath, request, "Subscription canceled.");
545543
}
546544
}
545+
546+
// Unrecognised action shape — surface an error rather than falling through to
547+
// an implicit undefined return, so callers always get a Response back.
548+
return redirectWithErrorMessage(callerPath, request, "Error setting plan", {
549+
ephemeral: false,
550+
});
547551
}
548552

549553
export async function setConcurrencyAddOn(organizationId: string, amount: number) {
@@ -556,7 +560,7 @@ export async function setConcurrencyAddOn(organizationId: string, amount: number
556560
return undefined;
557561
}
558562
return result;
559-
} catch (e) {
563+
} catch (_e) {
560564
recordPlatformFailure("setConcurrencyAddOn", "caught");
561565
return undefined;
562566
}
@@ -572,7 +576,7 @@ export async function setSeatsAddOn(organizationId: string, amount: number) {
572576
return undefined;
573577
}
574578
return result;
575-
} catch (e) {
579+
} catch (_e) {
576580
recordPlatformFailure("setSeatsAddOn", "caught");
577581
return undefined;
578582
}
@@ -588,7 +592,7 @@ export async function setBranchesAddOn(organizationId: string, amount: number) {
588592
return undefined;
589593
}
590594
return result;
591-
} catch (e) {
595+
} catch (_e) {
592596
recordPlatformFailure("setBranchesAddOn", "caught");
593597
return undefined;
594598
}
@@ -604,7 +608,7 @@ export async function setSchedulesAddOn(organizationId: string, amount: number)
604608
return undefined;
605609
}
606610
return result;
607-
} catch (e) {
611+
} catch (_e) {
608612
recordPlatformFailure("setSchedulesAddOn", "caught");
609613
return undefined;
610614
}
@@ -620,7 +624,7 @@ export async function getUsage(organizationId: string, { from, to }: { from: Dat
620624
return undefined;
621625
}
622626
return result;
623-
} catch (e) {
627+
} catch (_e) {
624628
recordPlatformFailure("getUsage", "caught");
625629
return undefined;
626630
}
@@ -643,7 +647,7 @@ export async function getCachedUsage(
643647
);
644648

645649
return result.val;
646-
} catch (e) {
650+
} catch (_e) {
647651
recordPlatformFailure("getCachedUsage", "caught");
648652
return undefined;
649653
}
@@ -659,7 +663,7 @@ export async function getUsageSeries(organizationId: string, params: UsageSeries
659663
return undefined;
660664
}
661665
return result;
662-
} catch (e) {
666+
} catch (_e) {
663667
recordPlatformFailure("getUsageSeries", "caught");
664668
return undefined;
665669
}
@@ -683,7 +687,7 @@ export async function reportInvocationUsage(
683687
return undefined;
684688
}
685689
return result;
686-
} catch (e) {
690+
} catch (_e) {
687691
recordPlatformFailure("reportInvocationUsage", "caught");
688692
return undefined;
689693
}
@@ -722,7 +726,7 @@ export async function getEntitlement(
722726
return undefined;
723727
}
724728
return response;
725-
} catch (e) {
729+
} catch (_e) {
726730
recordPlatformFailure("getEntitlement", "caught");
727731
return undefined;
728732
}
@@ -757,13 +761,16 @@ export async function getPromoCredits(organizationId: string): Promise<PromoCred
757761
const response = await client.promoCredits(organizationId);
758762
if (!response.success) {
759763
recordPlatformFailure("promoCredits", "no_success");
760-
return null;
764+
// Return undefined (not null) so SWR doesn't cache a transient failure
765+
// as "no credits" and hide the display for the stale TTL. null is
766+
// reserved for a successful "org has no promo credits" response.
767+
return undefined;
761768
}
762769
return response.promoCredits;
763-
} catch (e) {
770+
} catch (_e) {
764771
recordPlatformFailure("promoCredits", "caught");
765-
logger.error("promoCredits threw", { error: e });
766-
return null;
772+
logger.error("promoCredits threw", { error: _e });
773+
return undefined;
767774
}
768775
});
769776

@@ -792,7 +799,7 @@ export async function getBillingLimit(
792799
return undefined;
793800
}
794801
return response;
795-
} catch (e) {
802+
} catch (_e) {
796803
recordPlatformFailure("getBillingLimit", "caught");
797804
return undefined;
798805
}
@@ -803,7 +810,7 @@ export async function getBillingLimit(
803810
}
804811

805812
return result.val;
806-
} catch (e) {
813+
} catch (_e) {
807814
recordPlatformFailure("getBillingLimit", "caught");
808815
return undefined;
809816
}
@@ -877,7 +884,7 @@ export async function getActiveBillingLimits(): Promise<BillingLimitsActiveResul
877884
return undefined;
878885
}
879886
return response;
880-
} catch (e) {
887+
} catch (_e) {
881888
recordPlatformFailure("getActiveBillingLimits", "caught");
882889
return undefined;
883890
}
@@ -899,7 +906,7 @@ export async function getPendingBillingLimitResolves(): Promise<
899906
return undefined;
900907
}
901908
return response;
902-
} catch (e) {
909+
} catch (_e) {
903910
recordPlatformFailure("getPendingBillingLimitResolves", "caught");
904911
return undefined;
905912
}

0 commit comments

Comments
 (0)