bytic /
http
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Nip\Http\Kernel\Traits; |
||
| 4 | |||
| 5 | use Exception; |
||
| 6 | use Nip\Http\Exceptions\Handler; |
||
| 7 | use Nip\Http\Response\Response; |
||
| 8 | use Nip\Request; |
||
| 9 | use Psr\Http\Message\ResponseInterface; |
||
| 10 | use Psr\Http\Message\ServerRequestInterface; |
||
| 11 | use Throwable; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Trait HandleExceptions |
||
| 15 | * @package Nip\Http\Kernel\Traits |
||
| 16 | */ |
||
| 17 | trait HandleExceptions |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Report the exception to the exception handler. |
||
| 21 | * |
||
| 22 | * @param Exception $e |
||
| 23 | * @return void |
||
| 24 | */ |
||
| 25 | protected function reportException(Throwable $e) |
||
| 26 | { |
||
| 27 | app('log')->error($e); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param Request|ServerRequestInterface $request |
||
| 32 | * @param Exception $e |
||
| 33 | * @return Response|ResponseInterface |
||
| 34 | */ |
||
| 35 | protected function renderException($request, Throwable $e) |
||
| 36 | { |
||
| 37 | return (new Handler($this->getContainer()))->render($request, $e); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param Exception $e |
||
| 42 | * @param Request|ServerRequestInterface $request |
||
| 43 | * @return Response |
||
| 44 | */ |
||
| 45 | protected function handleException($request, Throwable $e) |
||
| 46 | { |
||
| 47 | $this->reportException($e); |
||
| 48 | |||
| 49 | return $this->renderException($request, $e); |
||
| 50 | } |
||
| 51 | } |
||
| 52 |