Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/middleware-retry/src/defaultStrategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ describe("defaultStrategy", () => {
});
});

it("handles non-standard errors", () => {
const nonStandardErrors = [undefined, "foo", { foo: "bar" }, 123, false, null];
const maxAttempts = 1;
const retryStrategy = new StandardRetryStrategy(() => Promise.resolve(maxAttempts));
for (const error of nonStandardErrors) {
next = jest.fn().mockRejectedValue(error);
expect(retryStrategy.retry(next, { request: { headers: {} } } as any)).rejects.toBeInstanceOf(Error);
}
});

describe("retryDecider init", () => {
it("sets defaultRetryDecider if options is undefined", () => {
const retryStrategy = new StandardRetryStrategy(() => Promise.resolve(maxAttempts));
Expand Down
10 changes: 9 additions & 1 deletion packages/middleware-retry/src/defaultStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export class StandardRetryStrategy implements RetryStrategy {
output.$metadata.totalRetryDelay = totalDelay;

return { response, output };
} catch (err) {
} catch (e) {
const err = asSdkError(e);
attempts++;
if (this.shouldRetry(err as SdkError, attempts, maxAttempts)) {
retryTokenAmount = this.retryQuota.retrieveRetryTokens(err);
Expand All @@ -154,3 +155,10 @@ export class StandardRetryStrategy implements RetryStrategy {
}
}
}

const asSdkError = (error: unknown): SdkError => {
if (error instanceof Error) return error;
if (error instanceof Object) return Object.assign(new Error(), error);
if (typeof error === "string") return new Error(error);
return new Error(`AWS SDK error wrapper for ${error}`);
};
2 changes: 1 addition & 1 deletion packages/smithy-client/src/sdk-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { MetadataBearer } from "@aws-sdk/types";

import { SmithyException } from "./exception";

export type SdkError = Error & SmithyException & MetadataBearer;
export type SdkError = Error & Partial<SmithyException> & Partial<MetadataBearer>;
6 changes: 4 additions & 2 deletions protocol_tests/aws-ec2/tests/functional/ec2query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import { Readable } from "stream";
/**
* Throws an expected exception that contains the serialized request.
*/
class EXPECTED_REQUEST_SERIALIZATION_ERROR {
constructor(readonly request: HttpRequest) {}
class EXPECTED_REQUEST_SERIALIZATION_ERROR extends Error {
constructor(readonly request: HttpRequest) {
super();
}
}

/**
Expand Down
6 changes: 4 additions & 2 deletions protocol_tests/aws-json/tests/functional/awsjson1_1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { Readable } from "stream";
/**
* Throws an expected exception that contains the serialized request.
*/
class EXPECTED_REQUEST_SERIALIZATION_ERROR {
constructor(readonly request: HttpRequest) {}
class EXPECTED_REQUEST_SERIALIZATION_ERROR extends Error {
constructor(readonly request: HttpRequest) {
super();
}
}

/**
Expand Down
6 changes: 4 additions & 2 deletions protocol_tests/aws-query/tests/functional/awsquery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ import { Readable } from "stream";
/**
* Throws an expected exception that contains the serialized request.
*/
class EXPECTED_REQUEST_SERIALIZATION_ERROR {
constructor(readonly request: HttpRequest) {}
class EXPECTED_REQUEST_SERIALIZATION_ERROR extends Error {
constructor(readonly request: HttpRequest) {
super();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ import { Readable } from "stream";
/**
* Throws an expected exception that contains the serialized request.
*/
class EXPECTED_REQUEST_SERIALIZATION_ERROR {
constructor(readonly request: HttpRequest) {}
class EXPECTED_REQUEST_SERIALIZATION_ERROR extends Error {
constructor(readonly request: HttpRequest) {
super();
}
}

/**
Expand Down
6 changes: 4 additions & 2 deletions protocol_tests/aws-restxml/tests/functional/restxml.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ import { Readable } from "stream";
/**
* Throws an expected exception that contains the serialized request.
*/
class EXPECTED_REQUEST_SERIALIZATION_ERROR {
constructor(readonly request: HttpRequest) {}
class EXPECTED_REQUEST_SERIALIZATION_ERROR extends Error {
constructor(readonly request: HttpRequest) {
super();
}
}

/**
Expand Down