Skip to content

Commit

Permalink
added HTTP 405 status custom page
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Nov 16, 2024
1 parent c7d0011 commit 12ac6fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/ErrorHandlerGetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Monolog\Logger;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpMethodNotAllowedException;
use Slim\Exception\HttpNotFoundException;
use Slim\Views\Twig;
use Throwable;
Expand Down Expand Up @@ -45,6 +46,13 @@ public function getErrorHandler(): callable
die;
}

if ($throwable instanceof HttpMethodNotAllowedException) {
http_response_code(405);
/** @phpstan-ignore-next-line shipmonk.checkedExceptionInCallable */
echo $this->twig->fetch('404.twig');
die;
}

$this->sentryCollector->collect($throwable);

$title = $inspector->getExceptionName();
Expand Down
1 change: 0 additions & 1 deletion src/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ public function getContainerDefinition(string $envPath, string $envFilename): ar
$container[FlashMessagesInterface::class] = autowire(FlashMessagesBySession::class);
$container[IMapper::class] = create(Mapper::class);
$container[IEntityFactory::class] = create(DefaultEntityFactory::class);
$container[IBankPaymentService::class] = autowire(FioBankPaymentService::class);
$container[SentryClient::class] = $sentryClient;
$container[SentryHub::class] = $sentryHub;

Expand Down
8 changes: 8 additions & 0 deletions src/Templates/translatable/405.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "_layout.twig" %}

{% block content %}
<div class="card card-half open-theme">
<h3>{% trans %}404.pardon{% endtrans %}</h3>
<a href="/" class="btn">{% trans %}404.button{% endtrans %}</a>
</div>
{% endblock %}

0 comments on commit 12ac6fa

Please sign in to comment.