@parmana/sdk behaves. If a guide and this page disagree, this page is right, and please report the guide. Every value here was read from the SDK source, and the retry behavior was tested against a server that fails on purpose.
Create a client
HttpTransport from the configuration you pass, so timeout, retryPolicy, apiKey and userAgent all apply. Two notes:
- On 1.1.5 and earlier, always pass
transport. Those versions throwConfigurationError: Transport is required.when it is missing, even though theConfigurationtype marks it optional. Use 1.1.6 or later to omit it. - If you supply your own transport, build it from the same configuration object.
HttpTransportreadstimeoutandretryPolicyfrom the configuration it is constructed with, not from the client. If you writenew HttpTransport({ endpoint, apiKey })next to aretryPolicyon the client, the transport never sees the retry policy and nothing is retried, with no error. Omittransportand this cannot happen.
Configuration options
Every request also carries
Content-Type: application/json.
Retries
Retries are off by default. They run only when bothretryPolicy.enabled is true and maxAttempts is above zero.
What is retried:
Tested: a server that returns
503 twice and then 200, and a client with enabled: true and maxAttempts: 3, made 3 requests and returned success. With a supplied transport built from a partial configuration the same client made 1 request and threw InternalServerError.
Errors
Every non 2xx response, and every failure to get one, is thrown as a typed error. There is no path where a failure looks like success.
Two
InternalServerError cases need different handling, and from 1.1.3 you can tell them apart with error.serverCode:
On 1.1.2 and earlier
serverCode is not on InternalServerError, so read the code from the error message.
Methods
The full signature of every method is in the API reference.
Idempotency
businessTransactionId is the idempotency key. Sending the same one twice returns 409 (ConflictError). The helper createBusinessTransaction() generates the identifiers and keeps the linked ones consistent, so use it instead of writing them by hand. The SDK never generates a businessTransactionId for you when you build the object yourself, and it never retries a POST, so a single call is a single attempt.