Compilation errors
The most common TypeScript compilation error when working with this SDK looks like:@aws-sdk/client-* packages in the same project depend on different versions of @smithy/types or @aws-sdk/types. Node’s module resolution can end up with multiple copies at different versions.
Fix: pin all @aws-sdk/client-* packages to the same version range.
package.json
The
<= prefix installs the greatest version at or below the given value. Not every minor version number is published for every package, since the monorepo version increments daily but packages are only published when they change.Runtime errors before a request is sent
Because the SDK provides a TypeScript API, it does not runtime-typecheck every value (that would increase bundle size). If you pass an incorrect type, the error may be thrown before any network request is made.Service errors: modeled vs unmodeled
Non-2xx responses from AWS services are thrown as JavaScriptError objects. The SDK distinguishes two kinds:
- Modeled errors are declared in the service model. For example,
NoSuchBucketis a modeled error for S3 — it appears in the list of named exceptions for each operation in the API reference. - Unmodeled errors are not in the service model. They may come from routing layers, load balancers, or security infrastructure in front of the service, or simply be incompletely modeled by the service team.
S3ServiceException for S3, LambdaServiceException for Lambda). Unmodeled errors are returned as an instance of this base class.
Handling service errors
The $metadata object
Every service exception includes a $metadata field:
| Field | Type | Description |
|---|---|---|
httpStatusCode | number | HTTP status code from the response |
requestId | string | Unique identifier for the request, useful for AWS support |
attempts | number | Number of request attempts made (including retries) |
totalRetryDelay | number | Total milliseconds spent waiting between retries |
Using instanceof with specific error classes
Parsing errors from service responses
If the SDK fails to parse an error response (for example, because a front-end layer returns plaintext when the service model expects JSON), the error message will include:$responseBodyText will contain the raw response body. It is not logged automatically to avoid accidental leaking of sensitive data.