Skip to content

Commit

Permalink
fix(middleware-serde): mark error entry non-enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Mar 15, 2022
1 parent c411f8d commit 3e95763
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/middleware-serde/src/deserializerMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("deserializerMiddleware", () => {
expect(mockDeserializer).toHaveBeenCalledWith(mockNextResponse.response, mockOptions);
});

it("injects $response reference to deserializing exceptions", async () => {
it("injects non-enumerable $response reference to deserializing exceptions", async () => {
const exception = Object.assign(new Error("MockException"), mockNextResponse.response);
mockDeserializer.mockReset();
mockDeserializer.mockRejectedValueOnce(exception);
Expand All @@ -73,6 +73,7 @@ describe("deserializerMiddleware", () => {
} catch (e) {
expect(e).toMatchObject(exception);
expect(e.$response).toEqual(mockNextResponse.response);
expect(Object.keys(e)).not.toContain("$response");
}
});
});
3 changes: 2 additions & 1 deletion packages/middleware-serde/src/deserializerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const deserializerMiddleware =
output: parsed as Output,
};
} catch (error) {
throw Object.assign(error, { $response: response });
Object.defineProperty(error, "$response", { value: response, enumerable: false });
throw error;
}
};

0 comments on commit 3e95763

Please sign in to comment.