MethodReturn<TData, TCode> discriminated union — it never throws for API errors. Always check result.success before accessing result.data.
The MethodReturn Pattern
TheMethodReturn<TData, TCode> type resolves to one of two shapes:
success flag first, then TypeScript narrows the type automatically:
Vivawallet, VivaISV, Marketplace) and every sub-client module.
Known Error Codes
Thecode field on a failure response is typed as a string literal so you can exhaustively handle specific conditions.
Most error codes are specific to the underlying VivaWallet API call. The
message field always contains the human-readable API error detail, which is the most reliable source for debugging any unexpected failure code.Handling Network and HTTP Errors
The SDK uses axios internally. HTTP error responses from the VivaWallet API (4xx / 5xx status codes) are caught by the SDK and translated into a{ success: false, message, code } failure response — you do not need to wrap SDK calls in try/catch to handle normal API errors.
try/catch:
Debugging Tips
- Log
result.message— this field contains the human-readable error description returned by the VivaWallet API and is the fastest path to understanding what went wrong. - Check your credentials — authentication-related errors (401/403) usually mean your
clientId,clientSecret,merchantId, orapikeyis incorrect or has been regenerated in the dashboard. - Use
dev: truewith demo credentials — initialize the SDK client withdev: truefor demo endpoints, and passdev: truetogetSmartCheckout()when generating a demo Smart Checkout URL. - Verify your source code — many payment order failures are caused by a source code that does not exist or is not correctly configured. Confirm the source code is active in your VivaWallet dashboard under Sales → Payment Sources.