From 34e98b948b009d451a5c98eea54ee9e6c6a421af Mon Sep 17 00:00:00 2001 From: Hasin Hayder Date: Fri, 20 May 2022 22:22:59 +0600 Subject: [PATCH] Friendly Message for MissingAbilityException --- app/Exceptions/Handler.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 912aaec..8fc1c4a 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -4,6 +4,7 @@ namespace App\Exceptions; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Laravel\Sanctum\Exceptions\MissingAbilityException; use Throwable; class Handler extends ExceptionHandler { @@ -54,6 +55,13 @@ class Handler extends ExceptionHandler { 'message'=>$exception->getMessage() ],404); } + + if ($exception instanceof MissingAbilityException) { + return response([ + 'error'=>1, + 'message'=>"Not authorized" + ],409); + } return parent::render($request, $exception); } }