AsaasException.php 501 B

12345678910111213141516171819202122
  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 function __construct(Response $response)
  9. {
  10. $status = $response->status();
  11. $body = $response->json();
  12. $this->errors = $body['errors'] ?? [];
  13. $message = "Asaas API Error ($status): " . collect($this->errors)->pluck('description')->join(', ');
  14. parent::__construct($message, $status);
  15. }
  16. }