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
8 changes: 7 additions & 1 deletion lib/Github/HttpClient/Plugin/GithubExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla
if (422 === $response->getStatusCode() && isset($content['errors'])) {
$errors = [];
foreach ($content['errors'] as $error) {
switch ($error['code']) {
switch ($error['code'] ?? null) {
case 'missing':
$errors[] = sprintf('The %s %s does not exist, for resource "%s"', $error['field'], $error['value'], $error['resource']);
break;
Expand All @@ -81,6 +81,12 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla
break;

default:
if (is_string($error)) {
$errors[] = $error;

break;
}

if (isset($error['message'])) {
$errors[] = $error['message'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testHandleRequest(ResponseInterface $response, ExceptionInterfac
if ($exception) {
$this->expectException(get_class($exception));
$this->expectExceptionCode($exception->getCode());
$this->expectExceptionMessage($exception->getMessage());
$this->expectExceptionMessageRegExp('/'.preg_quote($exception->getMessage(), '/').'$/');
}

$plugin->doHandleRequest(
Expand Down Expand Up @@ -196,6 +196,22 @@ public static function responseProvider()
),
'exception' => new \Github\Exception\RuntimeException('This endpoint requires you to be authenticated.', 401),
],
'Cannot delete active deployment' => [
'response' => new Response(
422,
[
'content-type' => 'application/json',
],
json_encode(
[
'message' => 'Validation Failed',
'errors' => ['We cannot delete an active deployment unless it is the only deployment in a given environment.'],
'documentation_url' => 'https://docs.github.com/rest/reference/repos#delete-a-deployment',
]
)
),
'exception' => new \Github\Exception\ValidationFailedException('Validation Failed: We cannot delete an active deployment unless it is the only deployment in a given environment.', 422),
],
];
}
}