Skip to content

Commit d7a8150

Browse files
committed
fix(smithy-client): decorateServiceException not to overwrite modeled members
1 parent 2eef0a4 commit d7a8150

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ describe("decorateServiceException", () => {
2929
expect(decorated.message).toBe("Error");
3030
});
3131

32+
it("should not overwrite the parsed exceptions", () => {
33+
const decorated = decorateServiceException(exception, { message: "Another Error" });
34+
expect(decorated.message).toBe("Error");
35+
});
36+
3237
it("should replace Message with message", () => {
3338
const decorated = decorateServiceException({
3439
name: "Error",

packages/smithy-client/src/exceptions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ export const decorateServiceException = <E extends ServiceException>(
4949
Object.entries(additions)
5050
.filter(([, v]) => v !== undefined)
5151
.forEach(([k, v]) => {
52-
// @ts-ignore assign unmodeled keys
53-
exception[k] = v;
52+
// @ts-ignore examine unmodeled keys
53+
if (exception[k] == undefined || exception[k] === "") {
54+
// @ts-ignore assign unmodeled keys
55+
exception[k] = v;
56+
}
5457
});
5558
// load error message from possible locations
5659
// @ts-expect-error message could exist in Message key.

0 commit comments

Comments
 (0)