Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-masks-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/core": patch
---

read code property of errors case-insensitively
14 changes: 13 additions & 1 deletion packages/core/src/submodules/cbor/parseCborBody.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test as it } from "vitest";

import { buildHttpRpcRequest } from "./parseCborBody";
import { buildHttpRpcRequest, loadSmithyRpcV2CborErrorCode } from "./parseCborBody";

describe("buildHttpRpcRequest", () => {
it("should copy the input headers", async () => {
Expand Down Expand Up @@ -30,3 +30,15 @@ describe("buildHttpRpcRequest", () => {
expect(request.headers).not.toBe(headers);
});
});

describe(loadSmithyRpcV2CborErrorCode.name, () => {
it("should read the code field case-insensitively", () => {
const code = loadSmithyRpcV2CborErrorCode(
{ statusCode: 200, headers: {} },
{
cOdE: "OhNoException:Sender",
}
);
expect(code).toEqual("OhNoException");
});
});
5 changes: 3 additions & 2 deletions packages/core/src/submodules/cbor/parseCborBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ export const loadSmithyRpcV2CborErrorCode = (output: HttpResponse, data: any): s
return sanitizeErrorCode(data["__type"]);
}

if (data.code !== undefined) {
return sanitizeErrorCode(data.code);
const codeKey = Object.keys(data).find((key) => key.toLowerCase() === "code");
if (codeKey && data[codeKey] !== undefined) {
return sanitizeErrorCode(data[codeKey]);
}
};

Expand Down
Loading