本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::getException方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseForExceptionEvent::getException方法的具体用法?PHP GetResponseForExceptionEvent::getException怎么用?PHP GetResponseForExceptionEvent::getException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
的用法示例。
在下文中一共展示了GetResponseForExceptionEvent::getException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
$this->logger->notice(sprintf('Exceptions catcher listener: catch kernel.exception event (exception: %s)', $event->getException()->getMessage()));
// If this is not a master request, skip handling
if (!$event->isMasterRequest()) {
$this->logger->debug('Exceptions catcher listener: this is not master request, skip');
return;
}
// If content already prepared
if ($event->hasResponse()) {
$this->logger->debug('Exceptions catcher listener: event already has response, skip');
return;
}
// Getting action
$apiServerAction = $event->getRequest()->attributes->get('apiAction');
/* @var $apiServerAction ApiServerAction */
// Something wrong
if (!$apiServerAction) {
$this->logger->error('Request parser listener: request has no apiAction attribute, sending empty response');
$event->setResponse(new JsonResponse([]));
return;
}
// Getting api server interface
$apiServerInterface = $apiServerAction->getApiServerInterface();
// Creating api response
$apiResponse = $apiServerInterface->getExceptionResponse($event->getException()->getMessage());
// Setting response
$event->setResponse(new JsonResponse($apiResponse->export()));
}
示例2: onKernelException
/**
* Register the event handler
*
* @param GetResponseForExceptionEvent $event
*
* @api
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!in_array(get_class($event->getException()), $this->checkExceptions)) {
return;
}
$exceptionMessage = $event->getException()->getMessage();
$prefixLength = mb_strlen($this->errorPrefix);
// PDO Exception likes to place SQLState before the message
// And do some other stuff...
// HT000 is used for MySQL, but there is no support for 'custom errors' yet
if ($event->getException() instanceof \PDOException) {
if (!in_array($event->getException()->getCode(), array('P0001'))) {
return;
}
// PostgreSQL
if ('P0001' === $event->getException()->getCode() && preg_match('#^SQLSTATE\\[P0001\\]: Raise exception: \\d+ ERROR: (.+)#', $exceptionMessage, $messageMatch)) {
$exceptionMessage = $messageMatch[1];
} else {
return;
}
// @codeCoverageIgnoreEnd
}
if (mb_substr($exceptionMessage, 0, $prefixLength) === $this->errorPrefix) {
$exceptionMessage = mb_substr($exceptionMessage, $prefixLength);
$messageMatch = $this->parseMessage($exceptionMessage);
$event->setException(new \Exception($this->translator->trans($messageMatch['message'], $messageMatch['params']), 0, $event->getException()));
}
}
示例3: onSilexError
public function onSilexError(GetResponseForExceptionEvent $event)
{
if (!$event->getException() instanceof \Bridge_Exception) {
return;
}
$e = $event->getException();
$request = $event->getRequest();
$params = ['account' => null, 'elements' => [], 'message' => $e->getMessage(), 'error_message' => null, 'notice_message' => null, 'file' => $e->getFile(), 'line' => $e->getLine(), 'r_method' => $request->getMethod(), 'r_action' => $request->getRequestUri(), 'r_parameters' => $request->getMethod() == 'GET' ? [] : $request->request->all()];
if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) {
$params = array_replace($params, ['account' => $this->app['bridge.account']]);
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200, ['X-Status-Code' => 200]);
} elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
$params = array_replace($params, ['account' => $this->app['bridge.account']]);
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, ['X-Status-Code' => 200]);
} elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
$params = array_replace($params, ['account' => $this->app['bridge.account']]);
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, ['X-Status-Code' => 200]);
} elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
$params = array_replace($params, ['api' => $e->get_api()]);
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200, ['X-Status-Code' => 200]);
} else {
$response = new Response($this->app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, ['X-Status-Code' => 200]);
}
$response->headers->set('Phrasea-StatusCode', 200);
$event->setResponse($response);
}
示例4: exceptionHandler
public function exceptionHandler(GetResponseForExceptionEvent $event)
{
if ($event->getException() instanceof PluginException) {
return;
}
$event->setException(new PluginException(sprintf('The plugin `%s` from bundle `%s` [%s] errored.', $this->plugin['plugin'], $this->bundleName, $this->pluginDef->getController()), null, $event->getException()));
}
示例5: handleKernelException
public function handleKernelException(GetResponseForExceptionEvent $event)
{
if ($this->container->get('kernel')->getEnvironment() !== 'dev') {
$exception = FlattenException::create($event->getException());
// First, log the exception to the standard error logs.
$this->container->get('logger')->error(' In File ' . $exception->getFile() . ', on line ' . $exception->getLine() . ': ' . $exception->getMessage());
// Determine what the HTTP status code should be.
if ($event->getException() instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
$httpStatusCode = $event->getException()->getStatusCode();
} else {
$httpStatusCode = $exception->getCode();
if ($exception->getCode() < 100 || $exception->getCode() >= 600) {
$httpStatusCode = 500;
}
}
$parameters = ['status_code' => $httpStatusCode, 'status_text' => $exception->getMessage(), 'exception' => $exception];
if (in_array('application/json', $event->getRequest()->getAcceptableContentTypes())) {
$errorContent = $this->container->get('templating')->render(':default:exception.json.twig', $parameters);
} else {
$errorContent = $this->container->get('templating')->render(':default:error.html.twig', $parameters);
}
$response = new Response($errorContent, $httpStatusCode);
$response->setProtocolVersion('1.1');
$event->setResponse($response);
}
}
示例6: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$response = new JsonResponse(['errorMessage' => $event->getException()->getMessage(), 'stackTrace' => $event->getException()->getTraceAsString()]);
if ($exception instanceof HttpExceptionInterface) {
$response->setStatusCode($exception->getStatusCode());
} else {
if ($exception instanceof AuthenticationException) {
$response->setData(['errorMessage' => 'You don\'t have permissions to do this.']);
$response->setStatusCode(Response::HTTP_FORBIDDEN);
} else {
if ($exception instanceof InvalidFormException) {
$errors = [];
foreach ($exception->getForm()->getErrors(true) as $error) {
if ($error->getOrigin()) {
$errors[$error->getOrigin()->getName()][] = $error->getMessage();
}
}
$data = ['errors' => $errors, 'errorMessage' => ''];
$response->setData($data);
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
} else {
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}
$event->setResponse($response);
}
示例7: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
// Skip HTTP exception
if ($event->getException() instanceof HttpException) {
return;
}
$this->setException($event->getException());
}
示例8: it_converts_numbers_to_http_status_code_exception
/**
* @test
*/
public function it_converts_numbers_to_http_status_code_exception()
{
$logger = \Phake::mock('Psr\\Log\\LoggerInterface');
$listener = new ConvertExceptionListener($logger, array('OutOfBoundsException' => 405));
$listener->onKernelException($event = new GetResponseForExceptionEvent(\Phake::mock('Symfony\\Component\\HttpKernel\\KernelInterface'), \Phake::mock('Symfony\\Component\\HttpFoundation\\Request'), 0, $original = new OutOfBoundsException()));
$this->assertInstanceOf('Symfony\\Component\\HttpKernel\\Exception\\HttpException', $event->getException());
$this->assertEquals(405, $event->getException()->getStatusCode());
$this->assertSame($original, $event->getException()->getPrevious());
}
示例9: onKernelException
/**
* onKernelException
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if ($exception instanceof HttpExceptionInterface) {
$code = $event->getException()->getStatusCode();
} else {
$code = 'unknown';
}
$this->eventDispatcher->dispatch('statsd.exception', new StatsdEvent($code));
}
示例10: onKernelException
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($this->kernel->getEnvironment() != 'dev') {
$exception = $event->getException();
if (!$exception instanceof HttpException) {
$this->logger->error($exception->getMessage());
}
$event->setResponse(new RedirectResponse($this->router->generate('music_error', ['code' => $event->getException() instanceof HttpException ? $exception->getStatusCode() : 500])));
}
}
示例11: onKernelException
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (false == $event->getException() instanceof ReplyInterface) {
return;
}
$response = $this->replyToSymfonyResponseConverter->convert($event->getException());
if (false == $response->headers->has('X-Status-Code')) {
$response->headers->set('X-Status-Code', $response->getStatusCode());
}
$event->setResponse($response);
}
示例12: onKernelException
/**
* Exception error handler
*
* @param GetResponseForExceptionEvent $event
*
* @return void
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($this->isIgnored($event->getException())) {
return;
}
if ($this->mailer) {
$this->mailer->sendException($event->getRequest(), $event->getException());
}
if ($this->statsd) {
$this->statsd->increment("exception");
}
}
示例13: onKernelException
/**
* If exception type is 404, display the Orchestra 404 node instead of Symfony exception
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($event->getException() instanceof DisplayBlockException) {
$event->getRequest()->setRequestFormat('fragment.' . $event->getRequest()->getRequestFormat());
$event->setException($event->getException()->getPrevious());
} elseif ($event->getException() instanceof HttpExceptionInterface && '404' == $event->getException()->getStatusCode()) {
$this->setCurrentSiteInfo(trim($this->request->getHost(), '/'), trim($this->request->getPathInfo(), '/'));
if ($html = $this->getCustom404Html()) {
$event->setResponse(new Response($html, 404));
}
}
}
示例14: onSilexError
/**
* {@inheritdoc}
*/
public function onSilexError(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$code = $exception->getCode();
if (is_numeric($code)) {
$code = max(1, intval($code));
} else {
$code = 1;
}
$this->app['console.status'] = $code;
$this->app['console']->renderException($event->getException(), $this->app['console.output']);
$event->setResponse(new Response());
}
示例15: onSilexError
public function onSilexError(GetResponseForExceptionEvent $event)
{
$handler = new DebugExceptionHandler($this->debug);
if (method_exists($handler, 'getHtml')) {
$exception = $event->getException();
if (!$exception instanceof FlattenException) {
$exception = FlattenException::create($exception);
}
$response = Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset(ini_get('default_charset'));
} else {
// BC with Symfony < 2.8
$response = $handler->createResponse($event->getException());
}
$event->setResponse($response);
}