You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If any methods in a Model Controller use a Policy via the Gate::allows() facade but throws a custom Exception, the OpenAPI specification generator bombs with the following:
The custom exception only reformats the fields of a base Exception to suit the project's frontend:
<?phpnamespaceApp\Exceptions;
useApp\Http\Responses\AcessoNegadoResponse;
useIlluminate\Http\JsonResponse;
useIlluminate\Http\Request;
useIlluminate\Http\Response;
class AcessoNegadoException extends \Exception
{
publicfunction__construct(
protectedstring$operacao,
$message = "",
$code = 0,
\Exception$previous = null,
)
{
parent::__construct($message, $code, $previous);
}
/** * Report the exception. */publicfunctionreport(): void
{
// Nada a Reportar
}
/** * Render the exception as an HTTP response. */publicfunctionrender(Request$request) : Response|JsonResponse
{
if ($request->wantsJson())
{
return (newAcessoNegadoResponse(mensagem: $this->message, operacao: $this->operacao))->toResponse($request);
}
abort(403);
}
}
(it works fine)
If the Gate check is changed to:
if (Gate::allows("pesquisar", Cliente::class))
instead of
if (!Gate::allows("pesquisar", Cliente::class))
(note the "!")
... then the OpenAPI specification generation does not fail anymore - but app logic is broken. If I add an "else" case to the inverted logic, the error is triggered again.
For now, the OpenAPI documentation simply is not required, so for now I simply ignore the error, but I want to know what's wrong with Scribe or if there is something inherently wrong with throwing custom access denied exceptions together with Scribe.
Scribe version
5.0.0
PHP version
8.3.6
Laravel version
11.43.1
Scribe config
What happened?
If any methods in a Model Controller use a Policy via the
Gate::allows()
facade but throws a custom Exception, the OpenAPI specification generator bombs with the following:The route is simple:
The Controller method is also simple:
The policy is also simple (only the relevant part pasted):
The custom exception only reformats the fields of a base
Exception
to suit the project's frontend:(it works fine)
If the
Gate
check is changed to:instead of
(note the "!")
... then the OpenAPI specification generation does not fail anymore - but app logic is broken. If I add an "else" case to the inverted logic, the error is triggered again.
For now, the OpenAPI documentation simply is not required, so for now I simply ignore the error, but I want to know what's wrong with Scribe or if there is something inherently wrong with throwing custom access denied exceptions together with Scribe.
Docs
The text was updated successfully, but these errors were encountered: