Skip to content

Commit 44a518d

Browse files
author
dante
committed
New exception for http calls
1 parent 8ae2e0f commit 44a518d

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace ProcessMaker\Exception;
4+
5+
use Exception;
6+
use GuzzleHttp\Psr7\Response;
7+
use Illuminate\Support\Str;
8+
9+
/**
10+
* Thrown if an expression failed to be parsed
11+
*
12+
* @package ProcessMaker\Exceptions
13+
*/
14+
15+
class HttpResponseException extends Exception
16+
{
17+
public $status;
18+
public $body;
19+
20+
/**
21+
* @param Response $response
22+
*/
23+
public function __construct(Response $response)
24+
{
25+
$this->status = $response->getStatusCode();
26+
$this->body = $response->getBody()->getContents();
27+
parent::__construct(__("Unexpected response (status=:status)\n:body", [
28+
'status' => $this->status,
29+
'body' => Str::limit($this->body, 100),
30+
]), 0);
31+
}
32+
}

‎ProcessMaker/Traits/MakeHttpRequests.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use GuzzleHttp\Psr7\Request;
1010
use GuzzleHttp\Psr7\Response;
1111
use Illuminate\Support\Arr;
12-
use ProcessMaker\Exception\DataSourceResponseException;
12+
use ProcessMaker\Exception\HttpResponseException;
1313
use Psr\Http\Message\ResponseInterface;
1414

1515
trait MakeHttpRequests
@@ -50,7 +50,7 @@ public function request(array $data = [], array $config = [])
5050
try {
5151
return $this->response($this->call(...$request), $data, $config, $mustache);
5252
} catch (ClientException $exception) {
53-
throw new DataSourceResponseException($exception->getResponse());
53+
throw new HttpResponseException($exception->getResponse());
5454
}
5555
}
5656

@@ -115,7 +115,7 @@ private function bearerAuthorization($method, $url, $headers, $body, $bodyType)
115115
* @param Mustache_Engine $mustache
116116
*
117117
* @return array
118-
* @throws DataSourceResponseException
118+
* @throws HttpResponseException
119119
*/
120120
private function response($response, array $data = [], array $config = [], Mustache_Engine $mustache)
121121
{
@@ -129,7 +129,7 @@ private function response($response, array $data = [], array $config = [], Musta
129129
$content = [];
130130
break;
131131
default:
132-
$exception = new DataSourceResponseException($response);
132+
$exception = new HttpResponseException($response);
133133
throw $exception;
134134
}
135135
$mapped = [];

0 commit comments

Comments
 (0)