Skip to content
This repository was archived by the owner on Dec 6, 2019. It is now read-only.

Commit e3c2b66

Browse files
committed
Corrige a conversão da exception
Para termos a mensagem correta ao obter um erro de requisição.
1 parent 59c95a3 commit e3c2b66

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Client/Client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function post($url, SimpleXMLElement $body)
4242

4343
return new SimpleXMLElement($response->getBody());
4444
} catch (RequestException $e) {
45-
throw new PagSeguroException($e->getMessage(), $e->getCode(), $e);
45+
throw PagSeguroException::create($e->getResponse());
4646
}
4747
}
4848

@@ -55,9 +55,10 @@ public function get($url)
5555
{
5656
try {
5757
$response = $this->client->request('GET', $url, ['verify' => false]);
58+
5859
return new SimpleXMLElement($response->getBody());
5960
} catch (RequestException $e) {
60-
throw new PagSeguroException($e->getMessage());
61+
throw PagSeguroException::create($e->getResponse());
6162
}
6263
}
6364
}

src/Client/PagSeguroException.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ class PagSeguroException extends \RuntimeException
77
{
88
/**
99
* @param ResponseInterface $response
10+
* @param \Exception|null $cause
1011
*
1112
* @return PagSeguroException
1213
*/
13-
public static function create(ResponseInterface $response)
14+
public static function create(ResponseInterface $response, \Exception $cause = null)
1415
{
15-
return new static(static::createMessage($response));
16+
return new static(static::createMessage($response), null, $cause);
1617
}
1718

1819
/**
@@ -22,8 +23,8 @@ public static function create(ResponseInterface $response)
2223
*/
2324
protected static function createMessage(ResponseInterface $response)
2425
{
25-
if ($response->getStatusCode() != 400) {
26-
return '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody(true);
26+
if ($response->getStatusCode() !== 400) {
27+
return '[' . $response->getStatusCode() . '] A HTTP error has occurred: ' . $response->getBody();
2728
}
2829

2930
$message = 'Some errors occurred:';

0 commit comments

Comments
 (0)