Skip to content

Commit c7cceb5

Browse files
authored
fix(middleware-serde): mark error entry non-enumerable (#3426)
1 parent 540aa8e commit c7cceb5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/middleware-serde/src/deserializerMiddleware.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("deserializerMiddleware", () => {
6363
expect(mockDeserializer).toHaveBeenCalledWith(mockNextResponse.response, mockOptions);
6464
});
6565

66-
it("injects $response reference to deserializing exceptions", async () => {
66+
it("injects non-enumerable $response reference to deserializing exceptions", async () => {
6767
const exception = Object.assign(new Error("MockException"), mockNextResponse.response);
6868
mockDeserializer.mockReset();
6969
mockDeserializer.mockRejectedValueOnce(exception);
@@ -73,6 +73,7 @@ describe("deserializerMiddleware", () => {
7373
} catch (e) {
7474
expect(e).toMatchObject(exception);
7575
expect(e.$response).toEqual(mockNextResponse.response);
76+
expect(Object.keys(e)).not.toContain("$response");
7677
}
7778
});
7879
});

packages/middleware-serde/src/deserializerMiddleware.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const deserializerMiddleware =
2222
output: parsed as Output,
2323
};
2424
} catch (error) {
25-
throw Object.assign(error, { $response: response });
25+
Object.defineProperty(error, "$response", {
26+
// configurable and enumerable defaults to `false` in Object.defineProperty
27+
value: response,
28+
});
29+
throw error;
2630
}
2731
};

0 commit comments

Comments
 (0)