@@ -59,8 +59,7 @@ public function testParsesClientErrorResponses(
5959 public static function errorResponsesProvider (): array
6060 {
6161 return [
62- // Error code in body
63- [
62+ 'error_code_in_body ' => [
6463 "HTTP/1.1 400 Bad Request \r\n" .
6564 "x-amzn-requestid: xyz \r\n\r\n" .
6665 '{ "type": "client", "message": "lorem ipsum", "code": "foo" } ' ,
@@ -79,8 +78,7 @@ public static function errorResponsesProvider(): array
7978 'body ' => [],
8079 ]
8180 ],
82- // Error code in header
83- [
81+ 'error_code_in_header ' => [
8482 "HTTP/1.1 400 Bad Request \r\n" .
8583 "x-amzn-RequestId: xyz \r\n" .
8684 "x-amzn-ErrorType: foo:bar \r\n\r\n" .
@@ -98,8 +96,7 @@ public static function errorResponsesProvider(): array
9896 'body ' => [],
9997 ]
10098 ],
101- // Error code in body, with service, modeled exception
102- [
99+ 'error_code_in_body_with_service_modeled_exception ' => [
103100 "HTTP/1.1 400 Bad Request \r\n" .
104101 "TestHeader: foo-header \r\n" .
105102 "x-meta-foo: foo-meta \r\n" .
@@ -135,8 +132,7 @@ public static function errorResponsesProvider(): array
135132 'error_shape ' => true
136133 ]
137134 ],
138- // Error code in header, with service, modeled exception
139- [
135+ 'error_code_in_header_with_service_modeled_exception ' => [
140136 "HTTP/1.1 400 Bad Request \r\n" .
141137 "TestHeader: foo-header \r\n" .
142138 "x-meta-foo: foo-meta \r\n" .
@@ -172,8 +168,7 @@ public static function errorResponsesProvider(): array
172168 'error_shape ' => true
173169 ]
174170 ],
175- // Error code in header, with service, unmodeled code
176- [
171+ 'error_code_in_header_with_service_unmodeled_code ' => [
177172 "HTTP/1.1 400 Bad Request \r\n" .
178173 "x-amzn-RequestId: xyz \r\n" .
179174 "x-amzn-ErrorType: NonExistentException \r\n\r\n" .
@@ -191,8 +186,7 @@ public static function errorResponsesProvider(): array
191186 'body ' => [],
192187 ]
193188 ],
194- // Error code in body, with service, unmodeled code
195- [
189+ 'error_code_in_body_with_service_unmodeled_code ' => [
196190 "HTTP/1.1 400 Bad Request \r\n" .
197191 "x-amzn-requestid: xyz \r\n\r\n" .
198192 '{ "type": "client", "message": "lorem ipsum", "code": "NonExistentException" } ' ,
@@ -211,8 +205,7 @@ public static function errorResponsesProvider(): array
211205 'body ' => [],
212206 ]
213207 ],
214- // Error code in body, with service, unmodeled code, capitalized message
215- [
208+ 'error_code_in_body_with_service_unmodeled_code_capitalized_message ' => [
216209 "HTTP/1.1 400 Bad Request \r\n" .
217210 "x-amzn-requestid: xyz \r\n\r\n" .
218211 '{ "type": "client", "Message": "lorem ipsum", "code": "NonExistentException" } ' ,
@@ -232,8 +225,7 @@ public static function errorResponsesProvider(): array
232225 'body ' => [],
233226 ]
234227 ],
235- // Test zero value in header
236- [
228+ 'test_zero_value_in_header ' => [
237229 "HTTP/1.1 400 Bad Request \r\n" .
238230 "TestHeader: 0 \r\n" .
239231 "x-amzn-requestid: xyz \r\n\r\n" .
@@ -254,8 +246,7 @@ public static function errorResponsesProvider(): array
254246 'error_shape ' => true
255247 ]
256248 ],
257- // Test false value in header
258- [
249+ 'test_false_value_in_header ' => [
259250 "HTTP/1.1 400 Bad Request \r\n" .
260251 "TestHeader: false \r\n" .
261252 "x-amzn-requestid: xyz \r\n\r\n" .
@@ -276,8 +267,7 @@ public static function errorResponsesProvider(): array
276267 'error_shape ' => true
277268 ]
278269 ],
279- // Test empty string in header (should be skipped)
280- [
270+ 'test_empty_string_in_header_should_be_skipped ' => [
281271 "HTTP/1.1 400 Bad Request \r\n" .
282272 "TestHeader: \r\n" .
283273 "x-amzn-requestid: xyz \r\n\r\n" .
@@ -297,6 +287,66 @@ public static function errorResponsesProvider(): array
297287 'message ' => null ,
298288 'error_shape ' => true
299289 ]
290+ ],
291+ 'error_description_as_message ' => [
292+ "HTTP/1.1 400 Bad Request \r\n" .
293+ "x-amzn-requestid: xyz \r\n\r\n" .
294+ '{ "code": "foo", "error_description": "error description text" } ' ,
295+ null ,
296+ false ,
297+ [
298+ 'code ' => 'foo ' ,
299+ 'message ' => 'error description text ' , // Expected here
300+ 'error_description ' => 'error description text ' ,
301+ 'type ' => 'client ' ,
302+ 'request_id ' => 'xyz ' ,
303+ 'parsed ' => [
304+ 'code ' => 'foo ' ,
305+ 'error_description ' => 'error description text '
306+ ],
307+ 'body ' => [],
308+ ]
309+ ],
310+ 'message_takes_precedence_over_error_description ' => [
311+ "HTTP/1.1 400 Bad Request \r\n" .
312+ "x-amzn-requestid: xyz \r\n\r\n" .
313+ '{ "code": "foo", "message": "primary message", "error_description": "fallback description" } ' ,
314+ null ,
315+ false ,
316+ [
317+ 'code ' => 'foo ' ,
318+ 'message ' => 'primary message ' , // Expected here
319+ 'error_description ' => 'fallback description ' ,
320+ 'type ' => 'client ' ,
321+ 'request_id ' => 'xyz ' ,
322+ 'parsed ' => [
323+ 'code ' => 'foo ' ,
324+ 'message ' => 'primary message ' ,
325+ 'error_description ' => 'fallback description '
326+ ],
327+ 'body ' => [],
328+ ]
329+ ],
330+ 'capital_message_takes_precedence_over_error_description ' => [
331+ "HTTP/1.1 400 Bad Request \r\n" .
332+ "x-amzn-requestid: xyz \r\n\r\n" .
333+ '{ "code": "foo", "Message": "primary message", "error_description": "fallback description" } ' ,
334+ null ,
335+ false ,
336+ [
337+ 'code ' => 'foo ' ,
338+ 'message ' => 'primary message ' , // Expected here
339+ 'Message ' => 'primary message ' ,
340+ 'error_description ' => 'fallback description ' ,
341+ 'type ' => 'client ' ,
342+ 'request_id ' => 'xyz ' ,
343+ 'parsed ' => [
344+ 'code ' => 'foo ' ,
345+ 'Message ' => 'primary message ' ,
346+ 'error_description ' => 'fallback description '
347+ ],
348+ 'body ' => [],
349+ ]
300350 ]
301351 ];
302352 }
0 commit comments