diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 9479aaaf2be..b8ee3a3325e 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -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']); diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 7cb7dfe33a8..c8b4dac7cb7 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -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), + ], ]; } }