Skip to content

Commit fde32e1

Browse files
committed
feat: add access denied HTTP exception renderable
1 parent c6aed63 commit fde32e1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

config/undefined.php

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
*/
5353

5454
'renderables' => [
55+
\RedExplosion\Undefined\Renderables\AccessDeniedHttpExceptionRenderable::class,
5556
\RedExplosion\Undefined\Renderables\AuthenticationExceptionRenderable::class,
5657
\RedExplosion\Undefined\Renderables\NotFoundHttpExceptionRenderable::class,
5758
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RedExplosion\Undefined\Renderables;
6+
7+
use Illuminate\Http\Request;
8+
use RedExplosion\Undefined\Enums\ErrorTypeEnum;
9+
use RedExplosion\Undefined\Responses\ErrorResponse;
10+
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
11+
12+
class AccessDeniedHttpExceptionRenderable
13+
{
14+
public function __invoke(AccessDeniedHttpException $exception, Request $request): ErrorResponse|null
15+
{
16+
if ($request->expectsJson()) {
17+
return new ErrorResponse(
18+
errorType: ErrorTypeEnum::InvalidRequestError,
19+
message: 'The provided key does not have the required permissions for this endpoint.',
20+
status: 401,
21+
);
22+
}
23+
24+
return null;
25+
}
26+
}

0 commit comments

Comments
 (0)