Skip to content

fixed php warning in GithubExceptionThrower #992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 4, 2021
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),
],
];
}
}