Skip to content

Commit

Permalink
Handle http exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cretueusebiu committed Jul 18, 2017
1 parent 2d71225 commit c904152
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
Expand Down Expand Up @@ -44,6 +47,15 @@ public function report(Exception $exception)
*/
public function render($request, Exception $exception)
{
if ($exception instanceOf AuthorizationException) {
return response()->json(['error' => 'Forbidden.'], 403);
}

if ($exception instanceof NotFoundHttpException ||
$exception instanceof ModelNotFoundException) {
return response()->json(['error' => 'Not found.'], 404);
}

return parent::render($request, $exception);
}

Expand Down

0 comments on commit c904152

Please sign in to comment.