From f84efb4527657a67b88c7f624b738a5c6e8c2e5d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 9 Jun 2020 22:52:15 +0200 Subject: [PATCH] Make invalid request error more clear --- lib/Github/HttpClient/Plugin/GithubExceptionThrower.php | 2 +- .../Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 04f137f06cf..dde0b45ccff 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -48,7 +48,7 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla $content = ResponseMediator::getContent($response); if (is_array($content) && isset($content['message'])) { if (400 === $response->getStatusCode()) { - throw new ErrorException($content['message'], 400); + throw new ErrorException(sprintf('%s (%s)', $content['message'], $response->getReasonPhrase()), 400); } if (422 === $response->getStatusCode() && isset($content['errors'])) { diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 84027aa4339..32be44ce1d5 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -92,11 +92,11 @@ public static function responseProvider() ], json_encode( [ - 'message' => 'Bad Request', + 'message' => 'Problems parsing JSON', ] ) ), - 'exception' => new \Github\Exception\ErrorException('Bad Request', 400), + 'exception' => new \Github\Exception\ErrorException('Problems parsing JSON (Bad Request)', 400), ], '422 Unprocessable Entity' => [ 'response' => new Response(