mirror of
https://github.com/flarum/core.git
synced 2025-08-17 22:01:44 +02:00
Use content for error page
This commit is contained in:
@@ -10,6 +10,9 @@
|
|||||||
namespace Flarum\Foundation\ErrorHandling;
|
namespace Flarum\Foundation\ErrorHandling;
|
||||||
|
|
||||||
use Flarum\Frontend\Controller;
|
use Flarum\Frontend\Controller;
|
||||||
|
use Flarum\Http\Content\PermissionDenied;
|
||||||
|
use Flarum\Http\Content\NotAuthenticated;
|
||||||
|
use Flarum\Http\Content\NotFound;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
@@ -55,6 +58,16 @@ class FrontendFormatter implements HttpFormatter
|
|||||||
{
|
{
|
||||||
$frontend = $this->container->make("flarum.frontend.forum");
|
$frontend = $this->container->make("flarum.frontend.forum");
|
||||||
|
|
||||||
|
if ($error->getStatusCode() === 401) {
|
||||||
|
$frontend->content(new NotAuthenticated);
|
||||||
|
}
|
||||||
|
elseif ($error->getStatusCode() === 403) {
|
||||||
|
$frontend->content(new PermissionDenied);
|
||||||
|
}
|
||||||
|
elseif ($error->getStatusCode() === 404) {
|
||||||
|
$frontend->content(new NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
return (new Controller($frontend))->handle($request)->withStatus($error->getStatusCode());
|
return (new Controller($frontend))->handle($request)->withStatus($error->getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
src/Http/Content/NotAuthenticated.php
Normal file
24
src/Http/Content/NotAuthenticated.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Http\Content;
|
||||||
|
|
||||||
|
use Flarum\Frontend\Document;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
|
class NotAuthenticated
|
||||||
|
{
|
||||||
|
public function __invoke(Document $document, Request $request)
|
||||||
|
{
|
||||||
|
$document->title = 'Not Authenticated';
|
||||||
|
$document->payload['errorCode'] = 103;
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
}
|
24
src/Http/Content/NotFound.php
Normal file
24
src/Http/Content/NotFound.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Http\Content;
|
||||||
|
|
||||||
|
use Flarum\Frontend\Document;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
|
class NotFound
|
||||||
|
{
|
||||||
|
public function __invoke(Document $document, Request $request)
|
||||||
|
{
|
||||||
|
$document->title = 'Not Found';
|
||||||
|
$document->payload['errorCode'] = 404;
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
}
|
24
src/Http/Content/PermissionDenied.php
Normal file
24
src/Http/Content/PermissionDenied.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Http\Content;
|
||||||
|
|
||||||
|
use Flarum\Frontend\Document;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
|
class PermissionDenied
|
||||||
|
{
|
||||||
|
public function __invoke(Document $document, Request $request)
|
||||||
|
{
|
||||||
|
$document->title = 'Permission Denied';
|
||||||
|
$document->payload['errorCode'] = 403;
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user