Skip to content

fix(smithy-client): exception option missing message property #3424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2022
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
23 changes: 22 additions & 1 deletion packages/smithy-client/src/exceptions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decorateServiceException, ServiceException } from "./exceptions";
import { decorateServiceException, ExceptionOptionType, ServiceException } from "./exceptions";

it("ServiceException extends from Error", () => {
expect(
Expand All @@ -11,6 +11,27 @@ it("ServiceException extends from Error", () => {
).toBeInstanceOf(Error);
});

it("ExceptionOptionType allows specifying message", () => {
class SomeException extends ServiceException {
readonly code: string;
constructor(opts: ExceptionOptionType<SomeException, ServiceException>) {
super({
name: "SomeException",
$fault: "client",
...opts,
});
this.code = opts.code;
}
}
const exception = new SomeException({
message: "message",
code: "code",
$metadata: {},
});
expect(exception.message).toBe("message");
expect(exception.code).toBe("code");
});

describe("decorateServiceException", () => {
const exception = new ServiceException({
name: "Error",
Expand Down
4 changes: 2 additions & 2 deletions packages/smithy-client/src/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { HttpResponse, MetadataBearer, ResponseMetadata, RetryableTrait, SmithyE
/**
* The type of the exception class constructor parameter. The returned type contains the properties
* in the `ExceptionType` but not in the `BaseExceptionType`. If the `BaseExceptionType` contains
* `$metadata` property, it's also included in the returned type.
* `$metadata` and `message` properties, it's also included in the returned type.
* @internal
*/
export type ExceptionOptionType<ExceptionType extends Error, BaseExceptionType extends Error> = Omit<
ExceptionType,
Exclude<keyof BaseExceptionType, "$metadata">
Exclude<keyof BaseExceptionType, "$metadata" | "message">
>;

export interface ServiceExceptionOptions extends SmithyException, MetadataBearer {
Expand Down