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: deserialize error from header #390

Merged
merged 1 commit into from
Oct 9, 2019
Merged
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
116 changes: 69 additions & 47 deletions clients/node/client-rds-data-node/protocol/AwsRestJson1_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,55 +96,37 @@ async function executeStatementAwsRestJson1_1DeserializeError(
output: HttpResponse
): Promise<ExecuteStatementResponse> {
let data = await parseBody(output);
if (output.statusCode === 400 && data.dbConnectionId !== undefined) {
return Promise.reject({
__type: "com.amazon.rdsdataservice#StatementTimeoutException",
$name: "StatementTimeoutException",
$fault: "client",
message: data.message,
dbConnectionId: data.dbConnectionId
});
let response: any;
switch (output.headers["x-amzn-ErrorType"]) {
case "BadRequestException":
case "com.amazon.rdsdataservice#BadRequestException":
response = badRequestExceptionDeserialize(data);
break;
case "StatementTimeoutException":
case "com.amazon.rdsdataservice#StatementTimeoutException":
response = statementTimeoutExceptionDeserialize(data);
break;
case "ForbiddenException":
case "com.amazon.rdsdataservice#ForbiddenException":
response = forbiddenExceptionDeserialize(data);
break;
case "InternalServerErrorException":
case "com.amazon.rdsdataservice#InternalServerErrorException":
response = internalServerErrorExceptionDeserialize(data);
break;
case "ServiceUnavailableError":
case "com.amazon.rdsdataservice#ServiceUnavailableError":
response = serviceUnavailableErrorDeserialize(data);
break;
default:
response = {
__type: "com.amazon.rdsdataservice#UnknownException",
$name: "UnknownException",
$fault: "server"
};
}

if (output.statusCode === 400) {
return Promise.reject({
__type: "com.amazon.rdsdataservice#BadRequestException",
$name: "BadRequestException",
$fault: "client",
message: data.message
});
}

if (output.statusCode === 403) {
return Promise.reject({
__type: "com.amazon.rdsdataservice#ForbiddenException",
$name: "ForbiddenException",
$fault: "client",
message: data.message
});
}

if (output.statusCode === 500) {
return Promise.reject({
__type: "com.amazon.rdsdataservice#InternalServerErrorException",
$name: "InternalServerErrorException",
$fault: "server"
});
}

if (output.statusCode === 503) {
return Promise.reject({
__type: "com.amazon.rdsdataservice#ServiceUnavailableError",
$name: "ServiceUnavailableError",
$fault: "server"
});
}

return Promise.reject({
__type: "com.amazon.rdsdataservice#UnknownException",
$name: "UnknownException",
$fault: "server"
});
return Promise.reject(response);
}

const sqlParameterListAwsRestJson1_1Serialize = (
Expand Down Expand Up @@ -308,6 +290,46 @@ const recordsAwsRestJson1_1Deserialize = (input: any): Array<Array<Field>> =>
const recordsListAwsRestJson1_1Deserialize = (input: any): Array<Field> =>
input && input.map((field: any) => fieldAwsRestJson1_1Deserialize(field));

const badRequestExceptionDeserialize = (input: any): BadRequestException => ({
__type: "com.amazon.rdsdataservice#BadRequestException",
$name: "BadRequestException",
$fault: "client",
message: input.message
});

const statementTimeoutExceptionDeserialize = (
input: any
): StatementTimeoutException => ({
__type: "com.amazon.rdsdataservice#StatementTimeoutException",
$name: "StatementTimeoutException",
$fault: "client",
message: input.message,
dbConnectionId: input.dbConnectionId
});

const forbiddenExceptionDeserialize = (input: any): ForbiddenException => ({
__type: "com.amazon.rdsdataservice#ForbiddenException",
$name: "ForbiddenException",
$fault: "client",
message: input.message
});

const internalServerErrorExceptionDeserialize = (
input: any
): InternalServerErrorException => ({
__type: "com.amazon.rdsdataservice#InternalServerErrorException",
$name: "InternalServerErrorException",
$fault: "server"
});

const serviceUnavailableErrorDeserialize = (
input: any
): ServiceUnavailableError => ({
__type: "com.amazon.rdsdataservice#ServiceUnavailableError",
$name: "ServiceUnavailableError",
$fault: "server"
});

const deserializeMetadata = (output: HttpResponse): ResponseMetadata => ({
httpStatusCode: output.statusCode,
httpHeaders: output.headers,
Expand Down