diff options
author | Frédéric Guillot <fred@kanboard.net> | 2018-03-02 13:41:37 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2018-03-02 13:41:37 -0800 |
commit | f92eb448cbee45640351c28855045d55ac258590 (patch) | |
tree | 670a345f30b36914030db8b3a36523dca55bf33b /app/Core | |
parent | ebe04e672c7982a1560133ee87f417560a851a10 (diff) |
Add response body to InvalidStatusException
Diffstat (limited to 'app/Core')
-rw-r--r-- | app/Core/Http/Client.php | 9 | ||||
-rw-r--r-- | app/Core/Http/InvalidStatusException.php | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/app/Core/Http/Client.php b/app/Core/Http/Client.php index de7c6ec6..3793fa33 100644 --- a/app/Core/Http/Client.php +++ b/app/Core/Http/Client.php @@ -164,7 +164,6 @@ class Client extends Base $startTime = microtime(true); $stream = @fopen(trim($url), 'r', false, stream_context_create($this->getContext($method, $content, $headers, $raiseForErrors))); - $response = ''; if (! is_resource($stream)) { $this->logger->error('HttpClient: request failed ('.$url.')'); @@ -176,14 +175,14 @@ class Client extends Base return ''; } - $response = stream_get_contents($stream); + $body = stream_get_contents($stream); $metadata = stream_get_meta_data($stream); if ($raiseForErrors && array_key_exists('wrapper_data', $metadata)) { $statusCode = $this->getStatusCode($metadata['wrapper_data']); if ($statusCode >= 400) { - throw new InvalidStatusException('Request failed with status code '.$statusCode, $statusCode); + throw new InvalidStatusException('Request failed with status code '.$statusCode, $statusCode, $body); } } @@ -192,11 +191,11 @@ class Client extends Base $this->logger->debug('HttpClient: headers='.var_export($headers, true)); $this->logger->debug('HttpClient: payload='.$content); $this->logger->debug('HttpClient: metadata='.var_export($metadata, true)); - $this->logger->debug('HttpClient: response='.$response); + $this->logger->debug('HttpClient: body='.$body); $this->logger->debug('HttpClient: executionTime='.(microtime(true) - $startTime)); } - return $response; + return $body; } /** diff --git a/app/Core/Http/InvalidStatusException.php b/app/Core/Http/InvalidStatusException.php index 2d4a8d36..9834fe65 100644 --- a/app/Core/Http/InvalidStatusException.php +++ b/app/Core/Http/InvalidStatusException.php @@ -5,15 +5,22 @@ namespace Kanboard\Core\Http; class InvalidStatusException extends ClientException { protected $statusCode = 0; + protected $body = ''; - public function __construct($message, $statusCode) + public function __construct($message, $statusCode, $body) { parent::__construct($message); $this->statusCode = $statusCode; + $this->body = $body; } public function getStatusCode() { return $this->statusCode; } + + public function getBody() + { + return $this->body; + } } |