Merge pull request from ArthurHoaro/fix/404-page

Properly handle 404 errors
This commit is contained in:
ArthurHoaro 2020-09-12 21:41:58 +02:00 committed by GitHub
commit 0d930454a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 121 additions and 5 deletions
application/front/controller/visitor

View file

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* Controller used to render the 404 error page.
*/
class ErrorNotFoundController extends ShaarliVisitorController
{
public function __invoke(Request $request, Response $response): Response
{
// Request from the API
if (false !== strpos($request->getRequestTarget(), '/api/v1')) {
return $response->withStatus(404);
}
// This is required because the middleware is ignored if the route is not found.
$this->container->basePath = rtrim($request->getUri()->getBasePath(), '/');
$this->assignView('error_message', t('Requested page could not be found.'));
return $response->withStatus(404)->write($this->render('404'));
}
}