Mensaje de error

This commit is contained in:
Juan Pablo Vial
2024-07-25 12:51:25 -04:00
parent b2f1bd5ba0
commit 081187e3d3
2 changed files with 24 additions and 1 deletions

View File

@ -10,5 +10,23 @@
<i class="hammer icon"></i> <i class="hammer icon"></i>
Esta parte del sitio está en construcción. Esta parte del sitio está en construcción.
</div> </div>
@if (isset($exception))
<div class="ui warning message">
<i class="exclamation triangle icon"></i>
<div class="content">
<div class="header">Error</div>
<p>{{$message}}</p>
</div>
</div>
@endif
@if (isset($error))
<div class="ui error message">
<i class="exclamation triangle icon"></i>
<div class="content">
<div class="header">Error</div>
<p>{{$message}}</p>
</div>
</div>
@endif
</div> </div>
@endsection @endsection

View File

@ -15,17 +15,22 @@ class Errors
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
{ {
$output = [];
try { try {
return $handler->handle($request); return $handler->handle($request);
} catch (Exception $exception) { } catch (Exception $exception) {
$output['message'] = $exception->getMessage();
$output['exception'] = $exception;
$this->logger->warning($exception); $this->logger->warning($exception);
} catch (Error $error) { } catch (Error $error) {
$output['message'] = $error->getMessage();
$output['error'] = $error;
$this->logger->error($error); $this->logger->error($error);
} }
$response = $this->responseFactory->createResponse(500, 'Internal Server Error'); $response = $this->responseFactory->createResponse(500, 'Internal Server Error');
if (str_contains($request->getUri()->getPath(), '/api')) { if (str_contains($request->getUri()->getPath(), '/api')) {
return $response; return $response;
} }
return $this->view->render($response, 'construccion'); return $this->view->render($response, 'construccion', $output);
} }
} }