Commit 06494ace authored by Matthias Adrowski's avatar Matthias Adrowski
Browse files

[TASK] Update RestController

parent 0796d9e4
......@@ -30,6 +30,7 @@ use Exception;
use SGalinski\SgRest\Service\Authentication\AuthenticationServiceInterface;
use SGalinski\SgRest\Service\DataResolveService;
use SGalinski\SgRest\Service\RegistrationService;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -163,9 +164,9 @@ abstract class AbstractRestController extends ActionController {
* @param ResponseInterface $response
* @throws Exception
*/
public function processRequest(RequestInterface $request, ResponseInterface $response): void {
public function processRequest(RequestInterface $request): \Psr\Http\Message\ResponseInterface {
try {
parent::processRequest($request, $response);
return parent::processRequest($request);
} catch (Exception $exception) {
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(self::class);
$logger->critical(
......@@ -177,10 +178,11 @@ abstract class AbstractRestController extends ActionController {
'trace' => $exception->getTraceAsString()
]
);
$this->response = new Response();
$this->response->setStatus($exception->getCode() < 1000 ? $exception->getCode() : 500);
$this->response->addAdditionalHeaderData($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
$this->response->appendContent(json_encode(['message' => $exception->getMessage()]));
return $this->response;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment