Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/nextrelease/chore-error-description-support.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "",
"description": "Handles errors that comes in the `error_description` field, specifically how SSO-OIDC service has it modeled."
}
]
4 changes: 3 additions & 1 deletion src/Api/ErrorParser/RestJsonErrorParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function __invoke(

// Retrieve error message directly
$data['message'] = $data['parsed']['message']
?? ($data['parsed']['Message'] ?? null);
?? $data['parsed']['Message']
?? $data['parsed']['error_description']
?? null;

$this->populateShape($data, $response, $command);

Expand Down
90 changes: 70 additions & 20 deletions tests/Api/ErrorParser/RestJsonErrorParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public function testParsesClientErrorResponses(
public static function errorResponsesProvider(): array
{
return [
// Error code in body
[
'error_code_in_body' => [
"HTTP/1.1 400 Bad Request\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'{ "type": "client", "message": "lorem ipsum", "code": "foo" }',
Expand All @@ -79,8 +78,7 @@ public static function errorResponsesProvider(): array
'body' => [],
]
],
// Error code in header
[
'error_code_in_header' => [
"HTTP/1.1 400 Bad Request\r\n" .
"x-amzn-RequestId: xyz\r\n" .
"x-amzn-ErrorType: foo:bar\r\n\r\n" .
Expand All @@ -98,8 +96,7 @@ public static function errorResponsesProvider(): array
'body' => [],
]
],
// Error code in body, with service, modeled exception
[
'error_code_in_body_with_service_modeled_exception' => [
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
Expand Down Expand Up @@ -135,8 +132,7 @@ public static function errorResponsesProvider(): array
'error_shape' => true
]
],
// Error code in header, with service, modeled exception
[
'error_code_in_header_with_service_modeled_exception' => [
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: foo-header\r\n" .
"x-meta-foo: foo-meta\r\n" .
Expand Down Expand Up @@ -172,8 +168,7 @@ public static function errorResponsesProvider(): array
'error_shape' => true
]
],
// Error code in header, with service, unmodeled code
[
'error_code_in_header_with_service_unmodeled_code' => [
"HTTP/1.1 400 Bad Request\r\n" .
"x-amzn-RequestId: xyz\r\n" .
"x-amzn-ErrorType: NonExistentException\r\n\r\n" .
Expand All @@ -191,8 +186,7 @@ public static function errorResponsesProvider(): array
'body' => [],
]
],
// Error code in body, with service, unmodeled code
[
'error_code_in_body_with_service_unmodeled_code' => [
"HTTP/1.1 400 Bad Request\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'{ "type": "client", "message": "lorem ipsum", "code": "NonExistentException" }',
Expand All @@ -211,8 +205,7 @@ public static function errorResponsesProvider(): array
'body' => [],
]
],
// Error code in body, with service, unmodeled code, capitalized message
[
'error_code_in_body_with_service_unmodeled_code_capitalized_message' => [
"HTTP/1.1 400 Bad Request\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'{ "type": "client", "Message": "lorem ipsum", "code": "NonExistentException" }',
Expand All @@ -232,8 +225,7 @@ public static function errorResponsesProvider(): array
'body' => [],
]
],
// Test zero value in header
[
'test_zero_value_in_header' => [
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: 0\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
Expand All @@ -254,8 +246,7 @@ public static function errorResponsesProvider(): array
'error_shape' => true
]
],
// Test false value in header
[
'test_false_value_in_header' => [
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: false\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
Expand All @@ -276,8 +267,7 @@ public static function errorResponsesProvider(): array
'error_shape' => true
]
],
// Test empty string in header (should be skipped)
[
'test_empty_string_in_header_should_be_skipped' => [
"HTTP/1.1 400 Bad Request\r\n" .
"TestHeader: \r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
Expand All @@ -297,6 +287,66 @@ public static function errorResponsesProvider(): array
'message' => null,
'error_shape' => true
]
],
'error_description_as_message' => [
"HTTP/1.1 400 Bad Request\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'{ "code": "foo", "error_description": "error description text" }',
null,
false,
[
'code' => 'foo',
'message' => 'error description text', // Expected here
'error_description' => 'error description text',
'type' => 'client',
'request_id' => 'xyz',
'parsed' => [
'code' => 'foo',
'error_description' => 'error description text'
],
'body' => [],
]
],
'message_takes_precedence_over_error_description' => [
"HTTP/1.1 400 Bad Request\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'{ "code": "foo", "message": "primary message", "error_description": "fallback description" }',
null,
false,
[
'code' => 'foo',
'message' => 'primary message', // Expected here
'error_description' => 'fallback description',
'type' => 'client',
'request_id' => 'xyz',
'parsed' => [
'code' => 'foo',
'message' => 'primary message',
'error_description' => 'fallback description'
],
'body' => [],
]
],
'capital_message_takes_precedence_over_error_description' => [
"HTTP/1.1 400 Bad Request\r\n" .
"x-amzn-requestid: xyz\r\n\r\n" .
'{ "code": "foo", "Message": "primary message", "error_description": "fallback description" }',
null,
false,
[
'code' => 'foo',
'message' => 'primary message', // Expected here
'Message' => 'primary message',
'error_description' => 'fallback description',
'type' => 'client',
'request_id' => 'xyz',
'parsed' => [
'code' => 'foo',
'Message' => 'primary message',
'error_description' => 'fallback description'
],
'body' => [],
]
]
];
}
Expand Down
Loading