mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-03-14 20:39:44 +01:00
Improvements to the exception handler
This commit is contained in:
parent
0cc0cdc9e3
commit
5ceb700b4c
@ -11,11 +11,11 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Exceptions;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\InvalidModelValidationException;
|
||||
use Exception;
|
||||
use GrahamCampbell\Exceptions\ExceptionHandler as ExceptionHandler;
|
||||
use GrahamCampbell\Exceptions\ExceptionHandler;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpNotFoundException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -25,7 +25,7 @@ class Handler extends ExceptionHandler
|
||||
* @var string[]
|
||||
*/
|
||||
protected $dontReport = [
|
||||
'Symfony\Component\HttpKernel\Exception\HttpException',
|
||||
HttpNotFoundException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@ -38,14 +38,8 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function render($request, Exception $e)
|
||||
{
|
||||
if ($request->is('api*')) {
|
||||
if ($e instanceof InvalidModelValidationException) {
|
||||
return Response::make(['status_code' => 400, 'message' => 'Bad Request'], 400);
|
||||
}
|
||||
|
||||
if ($e instanceof ModelNotFoundException) {
|
||||
return Response::make(['status_code' => 404, 'error' => 'Resource not found'], 404);
|
||||
}
|
||||
if ($e instanceof ModelNotFoundException) {
|
||||
$e = new HttpNotFoundException('Resource not found');
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user