-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✅ begun adding tests for exception handling * ✨ added exception handlers
- Loading branch information
1 parent
227dfb3
commit fdabfab
Showing
9 changed files
with
314 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,23 @@ | ||
<?php | ||
|
||
namespace Photogabble\Tuppence\ErrorHandlers; | ||
|
||
use Exception; | ||
use League\Route\Http\Exception\NotFoundException as RouteNotFoundException; | ||
use League\Container\Exception\NotFoundException as ContainerNotFoundException; | ||
use Zend\Diactoros\Response\JsonResponse; | ||
|
||
class DefaultExceptionHandler implements ExceptionHandler | ||
{ | ||
/** | ||
* @param Exception|RouteNotFoundException|ContainerNotFoundException $e | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function __invoke(Exception $e) | ||
{ | ||
return new JsonResponse([ | ||
'message' => $e->getMessage(), | ||
'trace' => explode(PHP_EOL, $e->getTraceAsString()) | ||
], (method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500)); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Photogabble\Tuppence\ErrorHandlers; | ||
|
||
interface ExceptionHandler | ||
{ | ||
/** | ||
* @param \Exception $e | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function __invoke(\Exception $e); | ||
} | ||
|
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,5 @@ | ||
<?php | ||
|
||
namespace Photogabble\Tuppence\ErrorHandlers; | ||
|
||
class InvalidHandlerException extends \Exception {} |
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,5 @@ | ||
<?php | ||
|
||
namespace Photogabble\Tuppence\ErrorHandlers; | ||
|
||
class InvalidHandlerResponseException extends \Exception {} |
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
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
Oops, something went wrong.