fix: broaden postOrder/postOrders return types to include ClobErrorResponseBody - #94
Open
osr21 wants to merge 1 commit into
Open
fix: broaden postOrder/postOrders return types to include ClobErrorResponseBody#94osr21 wants to merge 1 commit into
osr21 wants to merge 1 commit into
Conversation
…ponseBody
Since v1.1.0 the return type is Promise<OrderResponse> / Promise<OrderResponse[]>
but when throwOnError is false (the default) a failed submission resolves to
{ error: string; status: number } (ClobErrorResponseBody) at runtime.
TypeScript consumers see no compile-time warning and may access .orderID on
an error object, throwing a runtime exception.
Fix: change return types to:
postOrder → Promise<OrderResponse | ClobErrorResponseBody>
postOrders → Promise<(OrderResponse | ClobErrorResponseBody)[]>
ClobErrorResponseBody is already imported in client.ts.
Fixes: Polymarket#91
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
Since v1.1.0
postOrder()andpostOrders()returnPromise<OrderResponse>/Promise<OrderResponse[]>. But whenthrowOnErrorisfalse(the default), a failed submission resolves to{ error: string; status: number }(aClobErrorResponseBody) at runtime.TypeScript consumers get no compile-time warning. Accessing
.orderIDon an error object throws at runtime.Fix
Change the return types:
postOrder→Promise<OrderResponse | ClobErrorResponseBody>postOrders→Promise<(OrderResponse | ClobErrorResponseBody)[]>ClobErrorResponseBodyis already imported inclient.ts. A JSDoc comment on each method documents the union.Migration
Fixes #91
Note
Low Risk
Type-signature and documentation only; no runtime logic change, though TypeScript callers may need explicit error narrowing.
Overview
Broadens TypeScript return types so they match runtime behavior when
throwOnErroris false (the default): failed submissions can resolve to aClobErrorResponseBodyinstead of always looking like a successfulOrderResponse.createAndPostOrdernow returnsPromise<OrderResponse | ClobErrorResponseBody>, andpostOrdersreturnsPromise<(OrderResponse | ClobErrorResponseBody)[]>. Each method gets JSDoc noting that rejected/failed orders may appear as error bodies rather than thrown exceptions.Consumers should narrow results (e.g. check for
"error" in result) before reading fields likeorderID.Reviewed by Cursor Bugbot for commit 6b7dc09. Bugbot is set up for automated code reviews on this repo. Configure here.