From 0d6884a8a9ffc4f498503aafc993e399526647b0 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 29 Aug 2021 14:05:38 +0200 Subject: [PATCH] Fix `http_code` usage in case of failures --- src/Network/HTTPClient.php | 4 ++-- tests/src/Network/HTTPClientTest.php | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Network/HTTPClient.php b/src/Network/HTTPClient.php index 4467b2dea2..004af57f9a 100644 --- a/src/Network/HTTPClient.php +++ b/src/Network/HTTPClient.php @@ -146,11 +146,11 @@ class HTTPClient implements IHTTPClient $exception->hasResponse()) { return new GuzzleResponse($exception->getResponse(), $url, $exception->getCode(), ''); } else { - return new CurlResult($url, '', ['http_code' => $exception->getCode()], $exception->getCode(), ''); + return new CurlResult($url, '', ['http_code' => 500], $exception->getCode(), ''); } } catch (InvalidArgumentException | \InvalidArgumentException $argumentException) { $this->logger->info('Invalid Argument for HTTP call.', ['url' => $url, 'method' => $method, 'exception' => $argumentException]); - return new CurlResult($url, '', ['http_code' => $argumentException->getCode()], $argumentException->getCode(), $argumentException->getMessage()); + return new CurlResult($url, '', ['http_code' => 500], $argumentException->getCode(), $argumentException->getMessage()); } finally { $this->logger->debug('Request stop.', ['url' => $url, 'method' => $method]); $this->profiler->stopRecording(); diff --git a/tests/src/Network/HTTPClientTest.php b/tests/src/Network/HTTPClientTest.php index 89f2510f30..0e3f74c096 100644 --- a/tests/src/Network/HTTPClientTest.php +++ b/tests/src/Network/HTTPClientTest.php @@ -28,9 +28,6 @@ class HTTPClientTest extends MockedTest new Response(301, ['Location' => 'https:///']), ])); - $httpClient = DI::httpClient(); - $httpClient->get('https:///'); - - self::assertEquals(1,1); + self::assertFalse(DI::httpClient()->get('https://friendica.local')->isSuccess()); } }