Files
oficial/app/src/Middleware/Errors.php

32 lines
1.1 KiB
PHP
Raw Normal View History

2023-11-22 19:08:19 -03:00
<?php
namespace Incoviba\Middleware;
use Error;
use Exception;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Alias\View;
class Errors
{
public function __construct(protected LoggerInterface $logger, protected ResponseFactoryInterface $responseFactory, protected View $view) {}
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
return $handler->handle($request);
} catch (Exception $exception) {
2024-04-02 13:50:08 -03:00
$this->logger->warning($exception);
2023-11-22 19:08:19 -03:00
} catch (Error $error) {
$this->logger->error($error);
}
2024-01-08 21:25:02 -03:00
$response = $this->responseFactory->createResponse(600, 'Internal Server Error');
2023-11-22 19:08:19 -03:00
if (str_contains($request->getUri()->getPath(), '/api')) {
return $response;
}
return $this->view->render($response, 'construccion');
}
}