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
2 changes: 1 addition & 1 deletion lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl

if (422 === $response->getStatusCode() && isset($content['errors'])) {
$errors = [];
foreach ($content['errors'] as $error) {
foreach ((array) $content['errors'] as $error) {
switch ($error['code'] ?? null) {
case 'missing':
$errors[] = sprintf('The %s %s does not exist, for resource "%s"', $error['field'], $error['value'], $error['resource']);
Expand Down
16 changes: 16 additions & 0 deletions test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ public static function responseProvider()
),
'exception' => new \Github\Exception\ValidationFailedException('Validation Failed: We cannot delete an active deployment unless it is the only deployment in a given environment.', 422),
],
'Validation errors as a string' => [
'response' => new Response(
422,
[
'content-type' => 'application/json',
],
json_encode(
[
'message' => 'Validation Failed',
'errors' => 'No commit found for SHA: 1234567890abcdef',
'documentation_url' => 'https://docs.github.com/rest/commits/statuses#create-a-commit-status',
]
)
),
'exception' => new \Github\Exception\ValidationFailedException('Validation Failed: No commit found for SHA: 1234567890abcdef', 422),
],
];
}
}
Loading