1
0
mirror of https://github.com/flarum/core.git synced 2025-08-16 21:34:08 +02:00

Use content for error page

This commit is contained in:
Alexander Skvortsov
2020-07-28 21:37:42 -04:00
parent bf20ac663d
commit 7035625899
4 changed files with 85 additions and 0 deletions

View File

@@ -10,6 +10,9 @@
namespace Flarum\Foundation\ErrorHandling;
use Flarum\Frontend\Controller;
use Flarum\Http\Content\PermissionDenied;
use Flarum\Http\Content\NotAuthenticated;
use Flarum\Http\Content\NotFound;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Psr\Http\Message\ResponseInterface as Response;
@@ -55,6 +58,16 @@ class FrontendFormatter implements HttpFormatter
{
$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());
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}