Friendly Message for MissingAbilityException

pull/3/head
Hasin Hayder 3 years ago
parent c670d6a2fe
commit 34e98b948b

@ -4,6 +4,7 @@ namespace App\Exceptions;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Laravel\Sanctum\Exceptions\MissingAbilityException;
use Throwable; use Throwable;
class Handler extends ExceptionHandler { class Handler extends ExceptionHandler {
@ -54,6 +55,13 @@ class Handler extends ExceptionHandler {
'message'=>$exception->getMessage() 'message'=>$exception->getMessage()
],404); ],404);
} }
if ($exception instanceof MissingAbilityException) {
return response([
'error'=>1,
'message'=>"Not authorized"
],409);
}
return parent::render($request, $exception); return parent::render($request, $exception);
} }
} }

Loading…
Cancel
Save