mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
report 405s correctly
This commit is contained in:
parent
4f662ba9e1
commit
dcd3e22ad4
5 changed files with 31 additions and 3 deletions
|
@ -60,6 +60,12 @@ class Controller
|
|||
{
|
||||
return NavActions::execute404();
|
||||
}
|
||||
catch (\Routing\HttpMethodNotAllowedException $e)
|
||||
{
|
||||
Response::setStatus(405);
|
||||
Response::setHeader('Allow', implode(', ', $e->getAllowedMethods()));
|
||||
return ['page/404'];
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getRouterWithRoutes(): \Routing\RouteCollector
|
||||
|
|
|
@ -93,6 +93,7 @@ news:
|
|||
next: Next
|
||||
prev: Previous
|
||||
page:
|
||||
badmethod: HTTP method not allowed
|
||||
faq:
|
||||
back: Back to FAQ
|
||||
header: Frequently Asked Questions
|
||||
|
|
|
@ -175,7 +175,7 @@ class Dispatcher
|
|||
|
||||
$this->matchedRoute = $routes;
|
||||
|
||||
throw new HttpMethodNotAllowedException('Allow: ' . implode(', ', array_keys($routes)));
|
||||
throw new HttpMethodNotAllowedException(array_keys($routes), 'Method not allowed');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,4 +2,18 @@
|
|||
|
||||
namespace Routing;
|
||||
|
||||
class HttpMethodNotAllowedException extends HttpException {}
|
||||
class HttpMethodNotAllowedException extends HttpException
|
||||
{
|
||||
protected $allowedMethods;
|
||||
|
||||
public function __construct(array $allowedMethods, $message, $code, Exception $previous)
|
||||
{
|
||||
$this->allowedMethods = $allowedMethods;
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getAllowedMethods()
|
||||
{
|
||||
return $this->allowedMethods;
|
||||
}
|
||||
}
|
||||
|
|
7
view/template/page/405.php
Normal file
7
view/template/page/405.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php echo View::render('nav/_header', ['isDark' => false]) ?>
|
||||
<main>
|
||||
<div class="content">
|
||||
<h1>{{page.badmethod}}</h1>
|
||||
<p>{{page.funnier}}</p>
|
||||
</div>
|
||||
</main>
|
Loading…
Add table
Reference in a new issue