Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/utilities/hooks/useUpgradePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export const useUpgradeProduct = () => {
isTestUser,
});

if (!previewResponse) {
setPreviewError('Failed to fetch upgrade preview: 400');
return;
}
Comment thread
j-ruda-guardian marked this conversation as resolved.
Outdated

setMainPlan(mainPlan);
setSubscription(subscription);
setPreviewResponse(previewResponse);
Expand Down
5 changes: 5 additions & 0 deletions client/utilities/hooks/useUpgradeProductLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export const useUpgradeProductLoader = (): LoaderState => {
isTestUser: productDetail.isTestUser,
});

if (!preview) {
setState({ isLoading: false, shouldRedirect: true });
return;
}
Comment thread
j-ruda-guardian marked this conversation as resolved.
Outdated
Comment thread
j-ruda-guardian marked this conversation as resolved.
Comment thread
j-ruda-guardian marked this conversation as resolved.

setMainPlan(fetchedMainPlan);
setSubscription(productDetail.subscription);
setPreviewResponse(preview);
Expand Down
9 changes: 8 additions & 1 deletion client/utilities/productUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const changePlanFetch = ({
export const fetchUpgradePreviewData = async (params: {
subscriptionId: string;
isTestUser: boolean;
}): Promise<UpgradePreviewResponse> => {
}): Promise<UpgradePreviewResponse | null> => {
const response = await changePlanFetch({
subscriptionId: params.subscriptionId,
isTestUser: params.isTestUser,
Expand All @@ -287,6 +287,13 @@ export const fetchUpgradePreviewData = async (params: {
preview: true,
});

// A 400 means the user is ineligible for an online upgrade.
// Treat as "no preview available" rather than an error to avoid
// spurious Sentry noise for an expected business condition.
if (response.status === 400) {
return null;
}

if (!response.ok) {
throw new Error(`Failed to fetch upgrade preview: ${response.status}`);
}
Comment thread
j-ruda-guardian marked this conversation as resolved.
Expand Down
Loading