AsaasException.php 729 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Illuminate\Http\Client\Response;
  5. class AsaasException extends Exception
  6. {
  7. public array $errors;
  8. public $rawBody;
  9. public function __construct(Response $response)
  10. {
  11. $status = $response->status();
  12. $this->rawBody = $response->json() ?? $response->body();
  13. $body = $response->json();
  14. $this->errors = $body['errors'] ?? [];
  15. $message = "Asaas API Error ($status): " . collect($this->errors)->pluck('description')->join(', ');
  16. if (empty($this->errors) && is_string($this->rawBody)) {
  17. $message .= " | Response: " . $this->rawBody;
  18. }
  19. parent::__construct($message, $status);
  20. }
  21. }