fix: catch fetch errors in ensureBuilderFeeRateCached for browser compatibility - #96
Open
osr21 wants to merge 2 commits into
Open
fix: catch fetch errors in ensureBuilderFeeRateCached for browser compatibility#96osr21 wants to merge 2 commits into
osr21 wants to merge 2 commits into
Conversation
GET /fees/builder-fees/<code> returns 404 with no CORS headers. In browser
environments (Next.js, React, Vite etc.) every call to createOrder() or
createMarketOrder() therefore throws a CORS/network error before any order
is built, regardless of whether the user has a builderCode configured.
Fix: wrap the fetch in a try/catch. On failure default to {maker:0, taker:0}
so order creation is not blocked. The builder fee lookup is best-effort;
a non-fatal network or 404 error should not gate trading. Fixes Polymarket#51.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 7c68f68. Configure here.
…all race
If two callers invoke ensureBuilderFeeRateCached for the same builderCode
concurrently, one fetch may succeed while the other fails. The original
catch path unconditionally wrote { maker:0, taker:0 }, so whichever
settled last would win — the failure could silently replace real rates
with zeros for the rest of the client lifetime.
Fix: only write the zero fallback when the cache slot is still empty,
i.e. the successful path has not already populated it. Addressed feedback
from Cursor Bugbot review on PR Polymarket#96.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
@polymarket/clob-client-v2v1.0.1+ callsGET /fees/builder-fees/<code>insideensureBuilderFeeRateCachedon everycreateOrder()andcreateMarketOrder()call. This endpoint returns 404 with no CORS headers, which causes an immediate network/CORS error in any browser environment (Next.js, React, Vite, etc.) — before any order is signed or submitted.The result: order creation is completely broken in browsers for any user on v1.0.1+, even if they never set a
builderCode. This is because the method is also invoked viagetBuilderTakerFeeRateon thecreateMarketOrderpath.Root cause
Fix
Wrap the fetch in
try/catch. On failure, default to{ maker: 0, taker: 0 }. Builder fees are additive — defaulting to zero is safe and means order creation is not gated on a non-critical endpoint.Closes #51.
Note
Low Risk
Small defensive change on a non-critical fee lookup; worst case is underestimating builder fees in the browser when the API is unreachable.
Overview
ensureBuilderFeeRateCachedno longer lets a failedGET /fees/builder-fees/<code>abort order flows. The fetch is wrapped intry/catch, and on error the client caches{ maker: 0, taker: 0 }socreateMarketOrder/ buy-balance paths that call this helper can continue when the endpoint errors (e.g. 404 without CORS in the browser).The catch path only writes that zero fallback if the cache slot is still empty, so a concurrent successful fetch is not overwritten.
Reviewed by Cursor Bugbot for commit 9cebfe7. Bugbot is set up for automated code reviews on this repo. Configure here.