8000 Merge pull request #958 from pxgamer/feature/exception-handler-methods · laravel/lumen-framework@5d1d1ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d1d1ba

Browse files
authored
Merge pull request #958 from pxgamer/feature/exception-handler-methods
[5.8] Add support for reportable, renderable, and responsable exceptions
2 parents 877513f + 122856c commit 5d1d1ba

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Exceptions/Handler.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Illuminate\Http\Response;
7+
use Illuminate\Contracts\Support\Responsable;
78
use Illuminate\Validation\ValidationException;
89
use Illuminate\Contracts\Debug\ExceptionHandler;
910
use Illuminate\Auth\Access\AuthorizationException;
@@ -36,6 +37,10 @@ public function report(Exception $e)
3637
return;
3738
}
3839

40+
if (method_exists($e, 'report')) {
41+
return $e->report();
42+
}
43+
3944
try {
4045
$logger = app('Psr\Log\LoggerInterface');
4146
} catch (Exception $ex) {
@@ -82,6 +87,12 @@ protected function shouldntReport(Exception $e)
8287
*/
8388
public function render($request, Exception $e)
8489
{
90+
if (method_exists($e, 'render')) {
91+
return $e->render($request);
92+
} elseif ($e instanceof Responsable) {
93+
return $e->toResponse($request);
94+
}
95+
8596
if ($e instanceof HttpResponseException) {
8697
return $e->getResponse();
8798
} elseif ($e instanceof ModelNotFoundException) {

0 commit comments

Comments
 (0)
0