Skip to content

Commit

Permalink
feat(clients): fallback to status code for unmodeled errors (#3752)
Browse files Browse the repository at this point in the history
* chore(codegen): parseErrorCode returns optional string

* feat(clients): fallback to status code for unmodeled errors
  • Loading branch information
AllanZhengYP authored Jun 30, 2022
1 parent c59b7f5 commit 49bcc4f
Show file tree
Hide file tree
Showing 320 changed files with 59,514 additions and 48,290 deletions.
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

0 comments on commit 49bcc4f

Please sign in to comment.