@@ -3,7 +3,12 @@ import {
3
3
ExecuteStatementRequest ,
4
4
ExecuteStatementResponse ,
5
5
Field ,
6
- SqlParameter
6
+ SqlParameter ,
7
+ BadRequestException ,
8
+ StatementTimeoutException ,
9
+ ForbiddenException ,
10
+ InternalServerErrorException ,
11
+ ServiceUnavailableError
7
12
} from "../models/rdsdataservice" ;
8
13
import { HttpRequest , HttpResponse } from "@aws-sdk/protocol-http" ;
9
14
import * as __aws_sdk_stream_collector_node from "@aws-sdk/stream-collector-node" ;
@@ -60,13 +65,13 @@ export function executeStatementAwsRestJson1_1Serialize(
60
65
} ) ;
61
66
}
62
67
63
- export function executeStatementAwsRestJson1_1Deserialize (
68
+ export async function executeStatementAwsRestJson1_1Deserialize (
64
69
output : HttpResponse
65
70
) : Promise < ExecuteStatementResponse > {
66
71
if ( output . statusCode !== 200 ) {
67
72
return executeStatementAwsRestJson1_1DeserializeError ( output ) ;
68
73
}
69
- let data : any = parseBody ( output . body ) ;
74
+ let data : any = await parseBody ( output . body ) ;
70
75
return Promise . resolve ( {
71
76
__type : "com.amazon.rdsdataservice#ExecuteStatementResponse" ,
72
77
records : recordsAwsRestJson1_1Deserialize ( data . records ) ,
@@ -80,59 +85,42 @@ export function executeStatementAwsRestJson1_1Deserialize(
80
85
} ) ;
81
86
}
82
87
83
- function executeStatementAwsRestJson1_1DeserializeError (
88
+ async function executeStatementAwsRestJson1_1DeserializeError (
84
89
output : HttpResponse
85
90
) : Promise < ExecuteStatementResponse > {
86
- let data = parseBody ( output ) ;
87
- if ( output . statusCode === 400 && data . dbConnectionId !== undefined ) {
88
- return Promise . reject ( {
89
- __type : "com.amazon.rdsdataservice#StatementTimeoutException" ,
90
- $name : "StatementTimeoutException" ,
91
- $fault : "client" ,
92
- message : data . message ,
93
- dbConnectionId : data . dbConnectionId
94
- } ) ;
95
- }
96
-
97
- if ( output . statusCode === 400 ) {
98
- return Promise . reject ( {
99
- __type : "com.amazon.rdsdataservice#BadRequestException" ,
100
- $name : "BadRequestException" ,
101
- $fault : "client" ,
102
- message : data . message
103
- } ) ;
104
- }
105
-
106
- if ( output . statusCode === 403 ) {
107
- return Promise . reject ( {
108
- __type : "com.amazon.rdsdataservice#ForbiddenException" ,
109
- $name : "ForbiddenException" ,
110
- $fault : "client" ,
111
- message : data . message
112
- } ) ;
113
- }
114
-
115
- if ( output . statusCode === 500 ) {
116
- return Promise . reject ( {
117
- __type : "com.amazon.rdsdataservice#InternalServerErrorException" ,
118
- $name : "InternalServerErrorException" ,
119
- $fault : "server"
120
- } ) ;
121
- }
122
-
123
- if ( output . statusCode === 503 ) {
124
- return Promise . reject ( {
125
- __type : "com.amazon.rdsdataservice#ServiceUnavailableError" ,
126
- $name : "ServiceUnavailableError" ,
127
- $fault : "server"
128
- } ) ;
129
- }
130
-
131
- return Promise . reject ( {
132
- __type : "com.amazon.rdsdataservice#UnknownException" ,
133
- $name : "UnknownException" ,
134
- $fault : "server"
135
- } ) ;
91
+ const data : any = await parseBody ( output ) ;
92
+
93
+ let response : any ;
94
+ switch ( output . headers [ "x-amzn-ErrorType" ] ) {
95
+ case "BadRequestException" :
96
+ case "com.amazon.rdsdataservice#BadRequestException" :
97
+ response = badRequestExceptionDeserialize ( data ) ;
98
+ break ;
99
+ case "StatementTimeoutException" :
100
+ case "com.amazon.rdsdataservice#StatementTimeoutException" :
101
+ response = statementTimeoutExceptionDeserialize ( data ) ;
102
+ break ;
103
+ case "ForbiddenException" :
104
+ case "com.amazon.rdsdataservice#ForbiddenException" :
105
+ response = forbiddenExceptionDeserialize ( data ) ;
106
+ break ;
107
+ case "InternalServerErrorException" :
108
+ case "com.amazon.rdsdataservice#InternalServerErrorException" :
109
+ response = internalServerErrorExceptionDeserialize ( data ) ;
110
+ break ;
111
+ case "ServiceUnavailableError" :
112
+ case "com.amazon.rdsdataservice#ServiceUnavailableError" :
113
+ response = serviceUnavailableErrorDeserialize ( data ) ;
114
+ break ;
115
+ default :
116
+ response = {
117
+ __type : "com.amazon.rdsdataservice#UnknownException" ,
118
+ $name : "UnknownException" ,
119
+ $fault : "server"
120
+ } ;
121
+ }
122
+
123
+ return Promise . reject ( response ) ;
136
124
}
137
125
138
126
function sqlParameterListAwsRestJson1_1Serialize (
@@ -290,8 +278,58 @@ function recordsListAwsRestJson1_1Deserialize(input: any): Array<Field> {
290
278
return list ;
291
279
}
292
280
281
+ function badRequestExceptionDeserialize ( input : any ) : BadRequestException {
282
+ return {
283
+ __type : "com.amazon.rdsdataservice#BadRequestException" ,
284
+ $name : "BadRequestException" ,
285
+ $fault : "client" ,
286
+ message : input . message
287
+ } ;
288
+ }
289
+
290
+ function statementTimeoutExceptionDeserialize (
291
+ input : any
292
+ ) : StatementTimeoutException {
293
+ return {
294
+ __type : "com.amazon.rdsdataservice#StatementTimeoutException" ,
295
+ $name : "StatementTimeoutException" ,
296
+ $fault : "client" ,
297
+ message : input . message ,
298
+ dbConnectionId : input . dbConnectionId
299
+ } ;
300
+ }
301
+
302
+ function forbiddenExceptionDeserialize ( input : any ) : ForbiddenException {
303
+ return {
304
+ __type : "com.amazon.rdsdataservice#ForbiddenException" ,
305
+ $name : "ForbiddenException" ,
306
+ $fault : "client" ,
307
+ message : input . message
308
+ } ;
309
+ }
310
+
311
+ function internalServerErrorExceptionDeserialize (
312
+ input : any
313
+ ) : InternalServerErrorException {
314
+ return {
315
+ __type : "com.amazon.rdsdataservice#InternalServerErrorException" ,
316
+ $name : "InternalServerErrorException" ,
317
+ $fault : "server"
318
+ } ;
319
+ }
320
+
321
+ function serviceUnavailableErrorDeserialize (
322
+ input : any
323
+ ) : ServiceUnavailableError {
324
+ return {
325
+ __type : "com.amazon.rdsdataservice#ServiceUnavailableError" ,
326
+ $name : "ServiceUnavailableError" ,
327
+ $fault : "server"
328
+ } ;
329
+ }
330
+
293
331
function parseBody ( streamBody : any ) : any {
294
332
__aws_sdk_stream_collector_node . streamCollector ( streamBody ) . then ( body => {
295
- return __aws_sdk_util_utf8_node . toUtf8 ( body ) ;
333
+ return JSON . parse ( __aws_sdk_util_utf8_node . toUtf8 ( body ) ) ;
296
334
} ) ;
297
335
}
0 commit comments