fix: skip 400 responses in getCoinpayGlobalWalletTokens to allow fall…#266
fix: skip 400 responses in getCoinpayGlobalWalletTokens to allow fall…#266emil07770 wants to merge 1 commit into
Conversation
…back URLs
The getCoinpayGlobalWalletTokens function tries 3 CoinPay API endpoints in order but throws on HTTP 400 instead of continuing to the next URL. Adding 400 to the skip list allows fallback to /api/wallets and /api/businesses/{id} when /api/get-tokens returns 400.
Greptile SummaryAdds HTTP 400 to the set of status codes that trigger a
Confidence Score: 4/5The change is safe to merge; the worst case is two extra API calls before the existing error-throw path is reached. The change is minimal and the fallback loop already has correct final-error-surfacing logic, so correctness is maintained. The only open question is whether 400 can indicate a request-level misconfiguration that applies to all three endpoints equally, which would make the extra calls wasteful — but this does not break anything. src/lib/coinpayportal.ts — specifically the skip-list at line 564 and its interaction with the !sawSuccessfulResponse error path at line 574. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant GetTokens as /api/get-tokens
participant Wallets as /api/wallets
participant Businesses as /api/businesses/{id}
Client->>GetTokens: GET with Bearer token
alt 400 response
GetTokens-->>Client: 400 Bad Request
note over Client: continue to next URL (new behavior)
Client->>Wallets: GET with Bearer token
alt 200 OK
Wallets-->>Client: 200 + wallet list
Client-->>Client: return wallets
else 4xx skip code
Wallets-->>Client: 4xx
Client->>Businesses: GET with Bearer token
alt 200 OK
Businesses-->>Client: 200 + wallet list
Client-->>Client: return wallets
else all failed
Businesses-->>Client: 4xx
Client-->>Client: throw Error with first error
end
end
else 200 OK
GetTokens-->>Client: 200 + wallet list
Client-->>Client: return wallets
else 5xx or unrecognized 4xx
GetTokens-->>Client: 5xx
Client-->>Client: throw immediately
end
Reviews (1): Last reviewed commit: "fix: skip 400 responses in getCoinpayGlo..." | Re-trigger Greptile |
| if ([400, 401, 403, 404].includes(response.status)) continue; | ||
| throw new Error(`CoinPay get-tokens failed: ${response.status}`); |
There was a problem hiding this comment.
400 may also silence client-side misconfiguration on all three endpoints
HTTP 400 (Bad Request) typically signals a permanent client-side error — for example, a malformed business_id, an unsupported API version, or an invalid bearer token format. Because that root cause applies equally to all three URLs, adding 400 to the skip list can cause two extra round-trips before the function eventually throws via the !sawSuccessfulResponse path, with the diagnostic message buried in errors[0]. If CoinPay returns 400 specifically for endpoint-level reasons (e.g., /get-tokens requires a plan upgrade), the fallback is correct; but if it signals a request-level misconfiguration that affects all endpoints, the extra calls add latency without value. Consider whether a comment documenting the specific CoinPay behaviour that motivated this change would help future maintainers distinguish the two cases.
…back URLs
The getCoinpayGlobalWalletTokens function tries 3 CoinPay API endpoints in order but throws on HTTP 400 instead of continuing to the next URL. Adding 400 to the skip list allows fallback to /api/wallets and /api/businesses/{id} when /api/get-tokens returns 400.