Skip to content

Commit 31557b4

Browse files
committed
fix(core/protocols): read json error code case-insensitively
1 parent 22aaa56 commit 31557b4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, test as it } from "vitest";
2+
3+
import { loadRestJsonErrorCode } from "./parseJsonBody";
4+
5+
describe(loadRestJsonErrorCode.name, () => {
6+
it("reads the code of the error case-insensitively", () => {
7+
const code = loadRestJsonErrorCode(
8+
{ statusCode: 200, headers: {} },
9+
{
10+
cOdE: "OhNoException:Sender",
11+
}
12+
);
13+
expect(code).toEqual("OhNoException");
14+
});
15+
});

packages/core/src/submodules/protocols/json/parseJsonBody.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ export const loadRestJsonErrorCode = (output: HttpResponse, data: any): string |
5959
return sanitizeErrorCode(output.headers[headerKey]);
6060
}
6161

62-
if (data.code !== undefined) {
63-
return sanitizeErrorCode(data.code);
62+
const codeKey = findKey(data, "code");
63+
if (codeKey && data[codeKey] !== undefined) {
64+
return sanitizeErrorCode(data[codeKey]);
6465
}
6566

6667
if (data["__type"] !== undefined) {

0 commit comments

Comments
 (0)