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

feat(clients): fallback to status code for unmodeled errors #3752

Merged
merged 2 commits into from
Jun 30, 2022
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
256 changes: 141 additions & 115 deletions clients/client-accessanalyzer/src/protocols/Aws_restJson1.ts

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions clients/client-account/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ const deserializeAws_restJson1DeleteAlternateContactCommandError = async (
body: await parseBody(output.body, context),
};
let response: __BaseException;
let errorCode = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
case "com.amazonaws.account#AccessDeniedException":
Expand All @@ -160,10 +159,12 @@ const deserializeAws_restJson1DeleteAlternateContactCommandError = async (
throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode,
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata: deserializeMetadata(output),
$metadata,
});
throw __decorateServiceException(response, parsedBody);
}
Expand Down Expand Up @@ -196,8 +197,7 @@ const deserializeAws_restJson1GetAlternateContactCommandError = async (
body: await parseBody(output.body, context),
};
let response: __BaseException;
let errorCode = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
case "com.amazonaws.account#AccessDeniedException":
Expand All @@ -216,10 +216,12 @@ const deserializeAws_restJson1GetAlternateContactCommandError = async (
throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode,
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata: deserializeMetadata(output),
$metadata,
});
throw __decorateServiceException(response, parsedBody);
}
Expand Down Expand Up @@ -248,8 +250,7 @@ const deserializeAws_restJson1PutAlternateContactCommandError = async (
body: await parseBody(output.body, context),
};
let response: __BaseException;
let errorCode = "UnknownError";
errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
const errorCode = loadRestJsonErrorCode(output, parsedOutput.body);
switch (errorCode) {
case "AccessDeniedException":
case "com.amazonaws.account#AccessDeniedException":
Expand All @@ -265,10 +266,12 @@ const deserializeAws_restJson1PutAlternateContactCommandError = async (
throw await deserializeAws_restJson1ValidationExceptionResponse(parsedOutput, context);
default:
const parsedBody = parsedOutput.body;
const $metadata = deserializeMetadata(output);
const statusCode = $metadata.httpStatusCode ? $metadata.httpStatusCode + "" : undefined;
response = new __BaseException({
name: parsedBody.code || parsedBody.Code || errorCode,
name: parsedBody.code || parsedBody.Code || errorCode || statusCode || "UnknowError",
$fault: "client",
$metadata: deserializeMetadata(output),
$metadata,
});
throw __decorateServiceException(response, parsedBody);
}
Expand Down Expand Up @@ -401,7 +404,7 @@ const parseBody = (streamBody: any, context: __SerdeContext): any =>
/**
* Load an error code for the aws.rest-json-1.1 protocol.
*/
const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string => {
const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => {
const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());

const sanitizeErrorCode = (rawValue: string): string => {
Expand All @@ -427,6 +430,4 @@ const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string => {
if (data["__type"] !== undefined) {
return sanitizeErrorCode(data["__type"]);
}

return "";
};
Loading