Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,7 @@
"topupSuccess": "Credits added successfully",
"topupFailed": "Top-up failed",
"topupTimeout": "Top-up verification timed out",
"topupAlreadyPendingDetail": "A top-up you started earlier is still going through. Finish verifying it or wait for it to complete before adding more credits.",
"paymentDeclinedDetail": "Your bank declined this payment. Try another payment method or contact your bank.",
"insufficientFundsDetail": "This payment method has insufficient funds. Try another payment method or contact your bank.",
"expiredCardDetail": "This card has expired. Use a different payment method.",
Expand Down
17 changes: 17 additions & 0 deletions src/platform/workspace/billing/sdk/topupOperationView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ describe('projectTopupResult', () => {
)
})

it('names the earlier top-up still settling instead of an unknown error', () => {
expect(() =>
projectTopupResult(
{ status: 'error', code: 'OPERATION_ALREADY_PENDING' },
1000
)
).toThrow(
expect.objectContaining({
name: 'WorkspaceApiError',
code: 'OPERATION_ALREADY_PENDING',
failureCategory: 'stale_operation',
message:
'A top-up you started earlier is still going through. Finish verifying it or wait for it to complete before adding more credits.'
})
)
})

it('carries the HTTP status of a transport failure', () => {
let thrown: unknown
try {
Expand Down
12 changes: 8 additions & 4 deletions src/platform/workspace/billing/sdk/topupOperationView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,15 @@ export class UncreditedTopupResponse implements CreateTopupResponse {
) {}
}

/**
* Most SDK refusals carry no HTTP status, which a status-less API error
* would otherwise report as a network failure, so each names its category.
*/
function topupFailureError(failure: TopupFailure): WorkspaceApiError {
if (failure.code === 'OPERATION_ALREADY_PENDING') {
return new WorkspaceApiError(
t('billingOperation.topupAlreadyPendingDetail'),
undefined,
failure.code,
'stale_operation'
)
}
const serverCode = 'serverCode' in failure ? failure.serverCode : undefined
return new WorkspaceApiError(
t('credits.topUp.unknownError'),
Expand Down
Loading