| 12345678910111213141516171819202122232425262728 |
- <?php
- namespace App\Exceptions;
- use Exception;
- use Illuminate\Http\Client\Response;
- class AsaasException extends Exception
- {
- public array $errors;
- public $rawBody;
- public function __construct(Response $response)
- {
- $status = $response->status();
- $this->rawBody = $response->json() ?? $response->body();
- $body = $response->json();
- $this->errors = $body['errors'] ?? [];
- $message = "Asaas API Error ($status): " . collect($this->errors)->pluck('description')->join(', ');
-
- if (empty($this->errors) && is_string($this->rawBody)) {
- $message .= " | Response: " . $this->rawBody;
- }
- parent::__construct($message, $status);
- }
- }
|