From 427ebdc923c00d622bc3a83e3e68b1eb966af5c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20Sch=C3=BCle?=
Date: Mon, 13 Feb 2023 17:19:50 +0100
Subject: [PATCH] fix(Tinebase/Expressive): fix handling of 403 and 404
exceptions
---
.../Expressive/Middleware/ResponseEnvelop.php | 19 ++++++++++---------
tine20/Tinebase/Server/Expressive.php | 2 --
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/tine20/Tinebase/Expressive/Middleware/ResponseEnvelop.php b/tine20/Tinebase/Expressive/Middleware/ResponseEnvelop.php
index 15cf7b0c692..1e22ded8660 100644
--- a/tine20/Tinebase/Expressive/Middleware/ResponseEnvelop.php
+++ b/tine20/Tinebase/Expressive/Middleware/ResponseEnvelop.php
@@ -61,14 +61,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
//'resultsCount' => $response->resultCount !== null..
'status' => $response->getStatusCode()
]));
- } // else { TODO do something or remove this
- // maybe react to status !== 200
- // if client wants json envelop
- // if response->getStatusCode() !== 200
- // make body rewindable, writable, in doubt just create a new response or use withBody()
- // $response->getBody()->rewind();
- // $response->getBody()->write(json_encode(['results' => [], 'status' => $response->getStatusCode()]));
- //}
+ }
+ } catch (Tinebase_Exception_NotFound $tenf) {
+ if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(
+ __METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage());
+ $response = new Response($body = 'php://memory', Tinebase_Server_Expressive::HTTP_ERROR_CODE_NOT_FOUND);
+ } catch (Tinebase_Exception_AccessDenied $tead) {
+ if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(
+ __METHOD__ . '::' . __LINE__ . ' ' . $tead->getMessage());
+ $response = new Response($body = 'php://memory', Tinebase_Server_Expressive::HTTP_ERROR_CODE_FORBIDDEN);
} catch (Tinebase_Exception_Expressive_HttpStatus $teeh) {
// the exception can use logToSentry and logLevelMethod properties to achieve desired logging
// default is false (no sentry) and info log level
@@ -76,7 +77,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$response = new Response($body = 'php://memory', $teeh->getCode());
} catch (Exception $e) {
Tinebase_Exception::log($e, false);
- $response = new Response($body = 'php://memory', 500);
+ $response = new Response($body = 'php://memory', Tinebase_Server_Expressive::HTTP_ERROR_CODE_INTERNAL_SERVER_ERROR);
}
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
diff --git a/tine20/Tinebase/Server/Expressive.php b/tine20/Tinebase/Server/Expressive.php
index 52759ab05dd..c0468845352 100644
--- a/tine20/Tinebase/Server/Expressive.php
+++ b/tine20/Tinebase/Server/Expressive.php
@@ -93,8 +93,6 @@ public function handle(\Laminas\Http\Request $request = null, $body = null)
.' Is Routing request. uri: ' . $this->_request->getUri()->getPath() . '?'
. $this->_request->getUri()->getQuery() . ' method: ' . $this->_request->getMethod());
- $responsePrototype = new Response();
-
$middleWarePipe = new MiddlewarePipe();
$middleWarePipe->pipe(new Tinebase_Expressive_Middleware_ResponseEnvelop());
$middleWarePipe->pipe(new Tinebase_Expressive_Middleware_FastRoute());