- WIP on ApiRenderer and Save Form context@
This commit is contained in:
1 parent
78670c2fcf
commit
e51d1ea7a3
4 files changed
+107
-18
No files matched your search
@@ -5,16 +5,18 @@ namespace Lean\Api\Middleware;
|
||||
use Laminas\Diactoros\Response\JsonResponse;
|
||||
use Lean\Factory\HttpFactory;
|
||||
use Picea\Ui\Method\FormHandler;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Lean\Api\{Factory\DebugFormFactoryInterface, Form, Entity};
|
||||
use Lean\Api\{Controller\Debug, Factory\DebugFormFactoryInterface, Form, Entity};
|
||||
|
||||
class ApiRenderer implements MiddlewareInterface {
|
||||
|
||||
public function __construct(
|
||||
protected DebugFormFactoryInterface $debugFormFactory,
|
||||
protected ContainerInterface $container,
|
||||
# protected DebugFormFactoryInterface $debugFormFactory,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -25,6 +27,8 @@ class ApiRenderer implements MiddlewareInterface {
|
||||
}
|
||||
catch(\Throwable $ex) {
|
||||
if (static::awaitingJson($request)) {
|
||||
$this->saveError($request, $ex);
|
||||
|
||||
return HttpFactory::createJsonResponse([
|
||||
'status' => 'failed',
|
||||
'ts' => time(),
|
||||
@@ -59,21 +63,23 @@ class ApiRenderer implements MiddlewareInterface {
|
||||
|
||||
protected function saveError(ServerRequestInterface $request, \Throwable $exception) : Entity\Error
|
||||
{
|
||||
$request = $request->withMethod('PUT')->withParsedBody([]);
|
||||
if ($debugFormFactory = $this->container->get(DebugFormFactoryInterface::class)) {
|
||||
$request = $request->withMethod('PUT')->withParsedBody([]);
|
||||
|
||||
$context = $this->debugFormFactory->errorSaveContext($request);
|
||||
$context = $debugFormFactory->errorSaveContext($request);
|
||||
|
||||
$context->sets([
|
||||
'message' => $exception->getMessage(),
|
||||
'code' => $exception->getCode(),
|
||||
'file' => $exception->getFile(),
|
||||
'line' => $exception->getLine(),
|
||||
'trace' => $exception->getTrace(),
|
||||
]);
|
||||
$context->sets([
|
||||
'message' => $exception->getMessage(),
|
||||
'code' => $exception->getCode(),
|
||||
'file' => $exception->getFile(),
|
||||
'line' => $exception->getLine(),
|
||||
'trace' => $exception->getTrace(),
|
||||
]);
|
||||
|
||||
$form = $this->debugFormFactory->errorSave($entity = new Entity\Error());
|
||||
$form = $debugFormFactory->errorSave($entity = new Entity\Error());
|
||||
|
||||
new FormHandler($request, $form, $context);
|
||||
new FormHandler($request, $form, $context);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user