-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SNAPI-10272, SNAPI-11508] Add error handler.
- Loading branch information
1 parent
c54a378
commit e6d2986
Showing
3 changed files
with
87 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace SignNow\Rest\Service\Request\Handler; | ||
|
||
use Exception; | ||
use GuzzleHttp\Exception\RequestException; | ||
use SignNow\Rest\Entity\Error; | ||
|
||
/** | ||
* Class DefaultErrorHandler | ||
* | ||
* @package SignNow\Rest\Service\Request\Handler | ||
*/ | ||
class DefaultErrorHandler implements ErrorHandlerInterface | ||
{ | ||
/** | ||
* @param Exception $exception | ||
* | ||
* @return Error | ||
*/ | ||
public function handle(Exception $exception): Error | ||
{ | ||
$error = new Error(); | ||
$error->setResponse(($exception instanceof RequestException) ? $exception->getResponse() : null); | ||
$error->setMessage($exception->getMessage()); | ||
|
||
return $error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace SignNow\Rest\Service\Request\Handler; | ||
|
||
use Exception; | ||
use SignNow\Rest\Entity\Error; | ||
|
||
/** | ||
* Interface ErrorHandlerInterface | ||
* | ||
* @package SignNow\Rest\Service\Request\Handler | ||
*/ | ||
interface ErrorHandlerInterface | ||
{ | ||
/** | ||
* @param Exception $exception | ||
* | ||
* @return Error | ||
*/ | ||
public function handle(Exception $exception): Error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters