public function processRequest(RequestInterface $request, ResponseInterface $response)
{
try {
parent::processRequest($request, $response);
} catch (StopActionException $exception) {
throw $exception;
} catch (\Exception $exception) {
if ($this->request->getFormat() !== 'json' || !$response instanceof HttpResponse) {
throw $exception;
}
$exceptionData = $this->convertException($exception);
$response->setHeader('Content-Type', 'application/json');
if ($exception instanceof FlowException) {
$response->setStatus($exception->getStatusCode());
} else {
$response->setStatus(500);
}
$response->setContent(json_encode(array('error' => $exceptionData)));
$this->systemLogger->logException($exception);
}
}