|
1 | 1 | import { TypeRegistry } from "@smithy/core/schema"; |
2 | 2 | import { HttpResponse } from "@smithy/protocol-http"; |
3 | | -import { ServiceException, ServiceExceptionOptions } from "@smithy/smithy-client"; |
4 | | -import { StaticErrorSchema } from "@smithy/types"; |
| 3 | +import type { ServiceExceptionOptions } from "@smithy/smithy-client"; |
| 4 | +import { ServiceException } from "@smithy/smithy-client"; |
| 5 | +import type { StaticErrorSchema } from "@smithy/types"; |
5 | 6 | import { describe, expect, test as it } from "vitest"; |
6 | 7 |
|
7 | 8 | import { context } from "../test-schema.spec"; |
@@ -126,3 +127,46 @@ describe(AwsQueryProtocol.name, () => { |
126 | 127 | expect(actual.Error).toEqual(expected.Error); |
127 | 128 | }); |
128 | 129 | }); |
| 130 | + |
| 131 | +it("should not crash when error response body is empty", async () => { |
| 132 | + const httpResponse = new HttpResponse({ |
| 133 | + statusCode: 500, |
| 134 | + headers: { |
| 135 | + "content-type": "text/xml", |
| 136 | + }, |
| 137 | + body: Buffer.from(""), |
| 138 | + }); |
| 139 | + |
| 140 | + const protocol = new AwsQueryProtocol({ |
| 141 | + version: "1999-12-31", |
| 142 | + defaultNamespace: "com.amazonaws.giraffes", |
| 143 | + xmlNamespace: "ns", |
| 144 | + }); |
| 145 | + |
| 146 | + const actual = await protocol |
| 147 | + .deserializeResponse( |
| 148 | + { |
| 149 | + namespace: "ns", |
| 150 | + name: "Empty", |
| 151 | + traits: 0, |
| 152 | + input: "unit" as const, |
| 153 | + output: [3, "ns", "EmptyOutput", 0, [], []], |
| 154 | + }, |
| 155 | + context, |
| 156 | + httpResponse |
| 157 | + ) |
| 158 | + .catch((e) => { |
| 159 | + return e; |
| 160 | + }); |
| 161 | + |
| 162 | + // The error should be a proper ServiceException, not a raw TypeError |
| 163 | + expect(actual).toBeDefined(); |
| 164 | + expect(actual).not.toBeInstanceOf(TypeError); |
| 165 | + expect(actual.$metadata.httpStatusCode).toBe(500); |
| 166 | + expect(actual.message).toBe("Unknown"); |
| 167 | + expect(actual.Error).toEqual({ |
| 168 | + Type: undefined, |
| 169 | + Code: undefined, |
| 170 | + Message: "Unknown", |
| 171 | + }); |
| 172 | +}); |
0 commit comments