Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clients): populate message field when parsing error #3993

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
64 changes: 34 additions & 30 deletions clients/client-accessanalyzer/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ const deserializeAws_restJson1ApplyArchiveRuleCommandError = async (
): Promise<ApplyArchiveRuleCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -998,7 +998,7 @@ const deserializeAws_restJson1CancelPolicyGenerationCommandError = async (
): Promise<CancelPolicyGenerationCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1048,7 +1048,7 @@ const deserializeAws_restJson1CreateAccessPreviewCommandError = async (
): Promise<CreateAccessPreviewCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1107,7 +1107,7 @@ const deserializeAws_restJson1CreateAnalyzerCommandError = async (
): Promise<CreateAnalyzerCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1160,7 +1160,7 @@ const deserializeAws_restJson1CreateArchiveRuleCommandError = async (
): Promise<CreateArchiveRuleCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1216,7 +1216,7 @@ const deserializeAws_restJson1DeleteAnalyzerCommandError = async (
): Promise<DeleteAnalyzerCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1266,7 +1266,7 @@ const deserializeAws_restJson1DeleteArchiveRuleCommandError = async (
): Promise<DeleteArchiveRuleCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1319,7 +1319,7 @@ const deserializeAws_restJson1GetAccessPreviewCommandError = async (
): Promise<GetAccessPreviewCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1372,7 +1372,7 @@ const deserializeAws_restJson1GetAnalyzedResourceCommandError = async (
): Promise<GetAnalyzedResourceCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1425,7 +1425,7 @@ const deserializeAws_restJson1GetAnalyzerCommandError = async (
): Promise<GetAnalyzerCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1478,7 +1478,7 @@ const deserializeAws_restJson1GetArchiveRuleCommandError = async (
): Promise<GetArchiveRuleCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1531,7 +1531,7 @@ const deserializeAws_restJson1GetFindingCommandError = async (
): Promise<GetFindingCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1587,7 +1587,7 @@ const deserializeAws_restJson1GetGeneratedPolicyCommandError = async (
): Promise<GetGeneratedPolicyCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1640,7 +1640,7 @@ const deserializeAws_restJson1ListAccessPreviewFindingsCommandError = async (
): Promise<ListAccessPreviewFindingsCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1699,7 +1699,7 @@ const deserializeAws_restJson1ListAccessPreviewsCommandError = async (
): Promise<ListAccessPreviewsCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1755,7 +1755,7 @@ const deserializeAws_restJson1ListAnalyzedResourcesCommandError = async (
): Promise<ListAnalyzedResourcesCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1811,7 +1811,7 @@ const deserializeAws_restJson1ListAnalyzersCommandError = async (
): Promise<ListAnalyzersCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1864,7 +1864,7 @@ const deserializeAws_restJson1ListArchiveRulesCommandError = async (
): Promise<ListArchiveRulesCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1917,7 +1917,7 @@ const deserializeAws_restJson1ListFindingsCommandError = async (
): Promise<ListFindingsCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -1973,7 +1973,7 @@ const deserializeAws_restJson1ListPolicyGenerationsCommandError = async (
): Promise<ListPolicyGenerationsCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -2023,7 +2023,7 @@ const deserializeAws_restJson1ListTagsForResourceCommandError = async (
): Promise<ListTagsForResourceCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -2076,7 +2076,7 @@ const deserializeAws_restJson1StartPolicyGenerationCommandError = async (
): Promise<StartPolicyGenerationCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -2129,7 +2129,7 @@ const deserializeAws_restJson1StartResourceScanCommandError = async (
): Promise<StartResourceScanCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -2179,7 +2179,7 @@ const deserializeAws_restJson1TagResourceCommandError = async (
): Promise<TagResourceCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -2229,7 +2229,7 @@ const deserializeAws_restJson1UntagResourceCommandError = async (
): Promise<UntagResourceCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -2279,7 +2279,7 @@ const deserializeAws_restJson1UpdateArchiveRuleCommandError = async (
): Promise<UpdateArchiveRuleCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -2329,7 +2329,7 @@ const deserializeAws_restJson1UpdateFindingsCommandError = async (
): Promise<UpdateFindingsCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -2385,7 +2385,7 @@ const deserializeAws_restJson1ValidatePolicyCommandError = async (
): Promise<ValidatePolicyCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -3827,10 +3827,14 @@ const isSerializableHeaderValue = (value: any): boolean =>
(!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) &&
(!Object.getOwnPropertyNames(value).includes("size") || value.size != 0);

const parseBody = (streamBody: any, context: __SerdeContext): any =>
const parseBody = (streamBody: any, context: __SerdeContext & { $isError?: boolean }): any =>
collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
const value = JSON.parse(encoded);
if (context.$isError && value.Message !== undefined) {
value.message = value.Message;
}
return value;
}
return {};
});
Expand Down
18 changes: 11 additions & 7 deletions clients/client-account/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const deserializeAws_restJson1DeleteAlternateContactCommandError = async (
): Promise<DeleteAlternateContactCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -249,7 +249,7 @@ const deserializeAws_restJson1GetAlternateContactCommandError = async (
): Promise<GetAlternateContactCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -302,7 +302,7 @@ const deserializeAws_restJson1GetContactInformationCommandError = async (
): Promise<GetContactInformationCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -352,7 +352,7 @@ const deserializeAws_restJson1PutAlternateContactCommandError = async (
): Promise<PutAlternateContactCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -399,7 +399,7 @@ const deserializeAws_restJson1PutContactInformationCommandError = async (
): Promise<PutContactInformationCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
body: await parseBody(output.body, { ...context, $isError: true }),
};
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
Expand Down Expand Up @@ -577,10 +577,14 @@ const isSerializableHeaderValue = (value: any): boolean =>
(!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) &&
(!Object.getOwnPropertyNames(value).includes("size") || value.size != 0);

const parseBody = (streamBody: any, context: __SerdeContext): any =>
const parseBody = (streamBody: any, context: __SerdeContext & { $isError?: boolean }): any =>
collectBodyString(streamBody, context).then((encoded) => {
if (encoded.length) {
return JSON.parse(encoded);
const value = JSON.parse(encoded);
if (context.$isError && value.Message !== undefined) {
value.message = value.Message;
}
return value;
}
return {};
});
Expand Down