Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
peripherad
/
app
/
Exceptions
:
Handler.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php namespace App\Exceptions; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Http\Exceptions\ThrottleRequestsException; use Illuminate\Queue\Middleware\ThrottlesExceptions; use Illuminate\Routing\Middleware\ThrottleRequests; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Throwable; class Handler extends ExceptionHandler { /** * A list of the exception types that are not reported. * * @var array<int, class-string<Throwable>> */ protected $dontReport = [ // ]; /** * A list of the inputs that are never flashed for validation exceptions. * * @var array<int, string> */ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; /** * Register the exception handling callbacks for the application. * * @return void */ public function register() { $this->reportable(function (Throwable $e) { // }); } public function render($request, \Exception|Throwable $e) { if($e instanceof ModelNotFoundException) { if ($request->expectsJson()){ return response()->json([ 'message' => "Record not found.", 'errors' => ["error" => ["Record not found."]] ], Response::HTTP_NOT_FOUND); }else{ abort(Response::HTTP_NOT_FOUND); } } else if ($e instanceof NotFoundHttpException){ if ($request->expectsJson()){ return response()->json([ 'message' => "Invalid URL.", 'errors' => ["error" => ["Invalid URL."]] ], Response::HTTP_NOT_FOUND); }else{ abort(Response::HTTP_NOT_FOUND); } } else if ($e instanceof ThrottleRequestsException){ if ($request->expectsJson()){ return response()->json([ 'message' => "Please wait before retrying.", 'errors' => ["error" => ["Too many attempts."]] ], Response::HTTP_TOO_MANY_REQUESTS); }else{ abort(Response::HTTP_TOO_MANY_REQUESTS); } } return parent::render($request, $e); } }