Skip to content

Commit 6fc39be

Browse files
fix(smithy-client): exception option missing message property (#3424)
Co-authored-by: Eduardo Rodrigues <[email protected]>
1 parent 7f19c17 commit 6fc39be

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/smithy-client/src/exceptions.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { decorateServiceException, ServiceException } from "./exceptions";
1+
import { decorateServiceException, ExceptionOptionType, ServiceException } from "./exceptions";
22

33
it("ServiceException extends from Error", () => {
44
expect(
@@ -11,6 +11,27 @@ it("ServiceException extends from Error", () => {
1111
).toBeInstanceOf(Error);
1212
});
1313

14+
it("ExceptionOptionType allows specifying message", () => {
15+
class SomeException extends ServiceException {
16+
readonly code: string;
17+
constructor(opts: ExceptionOptionType<SomeException, ServiceException>) {
18+
super({
19+
name: "SomeException",
20+
$fault: "client",
21+
...opts,
22+
});
23+
this.code = opts.code;
24+
}
25+
}
26+
const exception = new SomeException({
27+
message: "message",
28+
code: "code",
29+
$metadata: {},
30+
});
31+
expect(exception.message).toBe("message");
32+
expect(exception.code).toBe("code");
33+
});
34+
1435
describe("decorateServiceException", () => {
1536
const exception = new ServiceException({
1637
name: "Error",

packages/smithy-client/src/exceptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { HttpResponse, MetadataBearer, ResponseMetadata, RetryableTrait, SmithyE
33
/**
44
* The type of the exception class constructor parameter. The returned type contains the properties
55
* in the `ExceptionType` but not in the `BaseExceptionType`. If the `BaseExceptionType` contains
6-
* `$metadata` property, it's also included in the returned type.
6+
* `$metadata` and `message` properties, it's also included in the returned type.
77
* @internal
88
*/
99
export type ExceptionOptionType<ExceptionType extends Error, BaseExceptionType extends Error> = Omit<
1010
ExceptionType,
11-
Exclude<keyof BaseExceptionType, "$metadata">
11+
Exclude<keyof BaseExceptionType, "$metadata" | "message">
1212
>;
1313

1414
export interface ServiceExceptionOptions extends SmithyException, MetadataBearer {

0 commit comments

Comments
 (0)