Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Tinebase/Expressive): fix handling of 403 and 404 exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pschuele committed Feb 13, 2023
1 parent 4c3a99a commit 427ebdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 10 additions & 9 deletions tine20/Tinebase/Expressive/Middleware/ResponseEnvelop.php
Expand Up @@ -61,22 +61,23 @@ 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
Tinebase_Exception::log($teeh);
$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)) {
Expand Down
2 changes: 0 additions & 2 deletions tine20/Tinebase/Server/Expressive.php
Expand Up @@ -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());
Expand Down

0 comments on commit 427ebdc

Please sign in to comment.