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
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { TypeRegistry } from "@smithy/core/schema";
import { HttpResponse } from "@smithy/protocol-http";
import { ServiceException, ServiceExceptionOptions } from "@smithy/smithy-client";
import { StaticErrorSchema } from "@smithy/types";
import type { ServiceExceptionOptions } from "@smithy/smithy-client";
import { ServiceException } from "@smithy/smithy-client";
import type { StaticErrorSchema } from "@smithy/types";
import { describe, expect, test as it } from "vitest";

import { context } from "../test-schema.spec";
Expand Down Expand Up @@ -126,3 +127,46 @@ describe(AwsQueryProtocol.name, () => {
expect(actual.Error).toEqual(expected.Error);
});
});

it("should not crash when error response body is empty", async () => {
const httpResponse = new HttpResponse({
statusCode: 500,
headers: {
"content-type": "text/xml",
},
body: Buffer.from(""),
});

const protocol = new AwsQueryProtocol({
version: "1999-12-31",
defaultNamespace: "com.amazonaws.giraffes",
xmlNamespace: "ns",
});

const actual = await protocol
.deserializeResponse(
{
namespace: "ns",
name: "Empty",
traits: 0,
input: "unit" as const,
output: [3, "ns", "EmptyOutput", 0, [], []],
},
context,
httpResponse
)
.catch((e) => {
return e;
});

// The error should be a proper ServiceException, not a raw TypeError
expect(actual).toBeDefined();
expect(actual).not.toBeInstanceOf(TypeError);
expect(actual.$metadata.httpStatusCode).toBe(500);
expect(actual.message).toBe("Unknown");
expect(actual.Error).toEqual({
Type: undefined,
Code: undefined,
Message: "Unknown",
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class AwsQueryProtocol extends RpcProtocol {
metadata: ResponseMetadata
): Promise<never> {
const errorIdentifier = this.loadQueryErrorCode(response, dataObject) ?? "Unknown";
const errorData = this.loadQueryError(dataObject);
const errorData = this.loadQueryError(dataObject) ?? {};
const message = this.loadQueryErrorMessage(dataObject);
errorData.message = message;
errorData.Error = {
Expand Down
Loading