public function handleRequest($request)
{
if (!$this->bootstrapped) {
return $this->internalServerError();
}
$this->currentRequest = $request;
/** @var Response $response */
$response = $this->get('response');
try {
$this->exec($request, $response);
} catch (\Exception $e) {
$response->data = $e;
$this->get('errorHandler')->handleException($e);
} catch (\Throwable $e) {
$response->data = $e;
$this->get('errorHandler')->handleException($e);
}
try {
$response->callMiddleware();
} catch (\Exception $e) {
$response->data = $e;
} catch (\Throwable $e) {
$response->data = $e;
}
$this->formatException($response->data, $response);
$response->prepare();
$this->refreshServices();
$this->currentRequest = null;
return $response;
}