APIError
will be thrown:
Status Code | Error Type |
---|---|
400 | BadRequestError |
401 | AuthenticationError |
403 | PermissionDeniedError |
404 | NotFoundError |
422 | UnprocessableEntityError |
429 | RateLimitError |
>=500 | InternalServerError |
N/A | APIConnectionError |
maxRetries
option to configure or disable this:
timeout
option:
APIConnectionTimeoutError
is thrown.
Note that requests which time out will be retried twice by default.
Response
returned by fetch()
can be accessed through the .asResponse()
method on the APIPromise
type that all methods return.
You can also use the .withResponse()
method to get the raw Response
along with the parsed data.
client.get
, client.post
, and other HTTP verbs.
Options on the client, such as retries, will be respected when making these requests.
// @ts-expect-error
on the undocumented
parameter. This library doesn’t validate at runtime that the request matches the type, so any extra values you
send will be sent as-is.
GET
verb, any extra params will be in the query, all other requests will send the
extra param in the body.
If you want to explicitly send an extra argument, you can do so with the query
, body
, and headers
request
options.
// @ts-expect-error
on
the response object, or cast the response object to the requisite type. Like the request params, we do not
validate or strip extra properties from the response from the API.
node-fetch
in Node, and expects a global fetch
function in other environments.
If you would prefer to use a global, web-standards-compliant fetch
function even in a Node environment,
(for example, if you are running Node with --experimental-fetch
or using NextJS which polyfills with undici
),
add the following import before your first import from "SnagSolutions"
:
import "@snagsolutions/sdk/shims/node"
(which does import polyfills).
This can also be useful if you are getting the wrong TypeScript types for Response
(more details).
fetch
function when instantiating the client,
which can be used to inspect or alter the Request
or Response
before/after each request:
DEBUG=true
environment variable, this library will log all requests and responses automatically.
This is intended for debugging purposes only and may change in the future without notice.
httpAgent
which is used for all requests (be they http or https), for example:
"node"
environment ("jsdom"
is not supported at this time).