Mejora en respuesta cuando no existe algun valor.
This commit is contained in:
@ -5,18 +5,25 @@ use Psr\Http\Message\ResponseFactoryInterface;
|
|||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\RequestHandlerInterface;
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Slim\Exception\HttpMethodNotAllowedException;
|
use Slim\Exception\HttpMethodNotAllowedException;
|
||||||
|
use Incoviba\Common\Alias\View;
|
||||||
|
|
||||||
class NotAllowed
|
class NotAllowed
|
||||||
{
|
{
|
||||||
public function __construct(protected ResponseFactoryInterface $responseFactory) {}
|
public function __construct(protected LoggerInterface $logger, protected ResponseFactoryInterface $responseFactory,
|
||||||
|
protected View $view) {}
|
||||||
|
|
||||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $handler->handle($request);
|
return $handler->handle($request);
|
||||||
} catch (HttpMethodNotAllowedException) {
|
} catch (HttpMethodNotAllowedException) {
|
||||||
return $this->responseFactory->createResponse(405, 'Method Not Allowed');
|
$response = $this->responseFactory->createResponse(405, 'Method Not Allowed');
|
||||||
|
if (str_contains($request->getUri()->getPath(), '/api')) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
return $this->view->render($response, 'not_allowed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,21 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Slim\Exception\HttpNotFoundException;
|
use Slim\Exception\HttpNotFoundException;
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Common\Implement\Exception\{EmptyRedis,EmptyResult};
|
||||||
|
use Incoviba\Exception\ServiceAction\{Create, Delete, Read, Update};
|
||||||
|
|
||||||
class NotFound
|
class NotFound
|
||||||
{
|
{
|
||||||
public function __construct(protected LoggerInterface $logger, protected ResponseFactoryInterface $responseFactory, protected View $view) {}
|
public function __construct(protected LoggerInterface $logger, protected ResponseFactoryInterface $responseFactory,
|
||||||
|
protected View $view) {}
|
||||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $handler->handle($request);
|
return $handler->handle($request);
|
||||||
} catch (HttpNotFoundException $exception) {
|
} catch (HttpNotFoundException |
|
||||||
|
EmptyRedis | EmptyResult | Read | Create | Update | Delete $exception) {
|
||||||
$this->logger->notice($exception);
|
$this->logger->notice($exception);
|
||||||
$response = $this->responseFactory->createResponse(404);
|
$response = $this->responseFactory->createResponse(404, 'Not Found');
|
||||||
if (str_contains($request->getUri()->getPath(), '/api')) {
|
if (str_contains($request->getUri()->getPath(), '/api')) {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user