Skip to content

Commit

Permalink
fix(smithy-client): decorateServiceException not to overwrite modeled…
Browse files Browse the repository at this point in the history
… members
  • Loading branch information
AllanZhengYP committed Feb 18, 2022
1 parent 717b06f commit 5c49c21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/smithy-client/src/exceptions.spec.ts
Expand Up @@ -29,6 +29,11 @@ describe("decorateServiceException", () => {
expect(decorated.message).toBe("Error");
});

it("should not overwrite the parsed exceptions", () => {
const decorated = decorateServiceException(exception, { message: "Another Error" });
expect(decorated.message).toBe("Error");
});

it("should replace Message with message", () => {
const decorated = decorateServiceException({
name: "Error",
Expand Down
7 changes: 5 additions & 2 deletions packages/smithy-client/src/exceptions.ts
Expand Up @@ -49,8 +49,11 @@ export const decorateServiceException = <E extends ServiceException>(
Object.entries(additions)
.filter(([, v]) => v !== undefined)
.forEach(([k, v]) => {
// @ts-ignore assign unmodeled keys
exception[k] = v;
// @ts-ignore examine unmodeled keys
if (exception[k] == undefined || exception[k] === "") {
// @ts-ignore assign unmodeled keys
exception[k] = v;
}
});
// load error message from possible locations
// @ts-expect-error message could exist in Message key.
Expand Down

0 comments on commit 5c49c21

Please sign in to comment.