Skip to content

Commit

Permalink
Guzzle
Browse files Browse the repository at this point in the history
Handling exceptions
  • Loading branch information
Walusyak committed Mar 1, 2022
1 parent 62e3cd7 commit c19b139
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Guzzle.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php
namespace ADT\Utils;

use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Psr7\Message;

class Guzzle {

/**
* @deprecated use handleException() instead
* Returns TRUE if everything is allright, FALSE if it's repetable error, otherwise throws exception
*
* \GuzzleHttp\Exception\GuzzleException $guzzleException
Expand All @@ -27,4 +33,13 @@ public static function handleError(\GuzzleHttp\Exception\GuzzleException $guzzle
throw $guzzleException;
}


public static function handleException(\Exception $e): ?\Throwable
{
return $e instanceof ServerException || $e instanceof ConnectException
? null
: ($e instanceof GuzzleException
? new \Exception(Psr7\Message::toString($e->getResponse()))
: $e);
}
}

0 comments on commit c19b139

Please sign in to comment.