working on exception handling for model not found.

This commit is contained in:
Taylor Otwell 2015-08-06 12:07:04 -05:00
parent 8061c2132c
commit da7376d461
1 changed files with 7 additions and 0 deletions

View File

@ -3,7 +3,9 @@
namespace App\Exceptions;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
@ -15,6 +17,7 @@ class Handler extends ExceptionHandler
*/
protected $dontReport = [
HttpException::class,
ModelNotFoundException::class,
];
/**
@ -39,6 +42,10 @@ public function report(Exception $e)
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException(404, $e->getMessage(), $e);
}
return parent::render($request, $e);
}
}