Thrown errors
UsePerpsErrorCode for type-safe handling:
Terms must be accepted first
Every non-metacreateAction and executeAction call fails with HTTP 401 and code 2012 (TermsNotAccepted) until the address has accepted the current terms version. That covers checkSetup (once the venue account exists), every setup step, trading and withdrawals. A terms-version bump gates the address again, including actions staged earlier.
Check and accept before any provider action:
Step results inside a successful response
A venue refusal (insufficient margin, invalid parameters, market closed) and an unclear venue answer both come back inside a202 response. placeOrder, placeTriggerOrder, placeTwapOrder, cancelOrders, modifyOrders, cancelTwapOrder, updatePositionMargin, sendAsset, withdraw, execute, executeProviderSetupAction, executeProviderOption, executeProviderRevoke and the meta methods resolve with { results } and do not throw on it. 202 does not mean that the venue accepted a step. Read the status of every result:
The report holds only the steps that the backend attempted. It stops at the first
Failed or Indeterminate step. Earlier acknowledgements stay in the report. Every member of an attempted atomic batch has a result, and two steps with the same action keep two results. This example handles every result:
ActionResult is one flat type. error is set unless the status is Submitted or Accepted, and errorCode is set when the cause is classified. orderId, twapId, txHash and explorerLink are set when the venue and the provider give them.
Returned result or thrown error
- A returned
Failedresult is a confirmed refusal of one step, with the steps before it kept in the report. AFailedresult after verification can also come from a step that the backend first reported asSubmittedorIndeterminate. The response that you hold does not show that change. - A thrown
PerpsErroris a request, signing or transport failure with no report from the backend. Nothing in your hands says what the venue did. - A thrown
PerpsExecutionErrormeans that a later stage failed after some results were known. Itsresponse.resultsholds every known result, andcauseholds the original error. Read the results before you handle the error.
SDK-originated messages
PerpsErrorMessage pairs canonical human-readable text with PerpsErrors the SDK itself raises (not the backend’s error responses): AgentNotFound (agent-signing setup incomplete) and AgentStorageCorrupt (a stored agent keypair is malformed and the agent must be revoked and re-approved). Both are thrown as PerpsErrorCode.SDKError (2005), so compare error.message.
Common Trading Errors
See Error Codes for the complete reference, including how
errorCodeFromStatus resolves a code from an HTTP status.