misuzu/src/RoutingErrorHandler.php

30 lines
986 B
PHP
Raw Normal View History

2024-03-30 03:14:03 +00:00
<?php
namespace Misuzu;
use Index\Http\{HttpResponseBuilder,HttpRequest};
use Index\Http\ErrorHandling\HtmlErrorHandler;
class RoutingErrorHandler extends HtmlErrorHandler {
public function handle(HttpResponseBuilder $response, HttpRequest $request, int $code, string $message): void {
if(str_starts_with($request->getPath(), '/_')) {
$response->setTypePlain();
$response->setContent(sprintf('HTTP %03d', $code));
return;
}
if($code === 500 || $code === 503) {
$response->setTypeHTML();
2024-03-30 03:19:08 +00:00
$response->setContent(file_get_contents(sprintf('%s/%03d.html', MSZ_TEMPLATES, $code)));
2024-03-30 03:14:03 +00:00
return;
}
if($code === 401 || $code === 403 || $code === 404) {
$response->setTypeHTML();
$response->setContent(Template::renderRaw(sprintf('errors.%03d', $code)));
return;
}
parent::handle($response, $request, $code, $message);
}
}