Should not handle Validation Exceptions and only service exceptions

@param GetResponseForExceptionEvent $event Sf Event

@return void
337612
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();

        // Should return a error 400 bad request
        if ($exception instanceof ValidationException
         || $exception instanceof SyntaxErrorException) {
            return;
        }

        // Some Exceptions have status code and if 400 it should be handled by them
        if (method_exists($exception, 'getStatusCode')
            && (400 == (int)$exception->getStatusCode())) {
            return;
        }

        $data = $this->decorateKnownCases($exception);

        if (!is_array($data)) {
            $data = [
                'code' => $exception->getCode(),
                'exceptionClass' => get_class($exception),
                'message' => $exception->getMessage()
            ];

            if ($exception->getPrevious() instanceof \Exception) {
                $data['innerMessage'] = $exception->getPrevious()->getMessage();
            }
        }

        if ($this->logger instanceof Logger) {
            $this->logger->critical($exception);
        }

        $response = new JsonResponse($data);
        $event->setResponse($response);
    }
1122788
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        if ($event->getException() instanceof NotFoundHttpException && $this->cmsManagerSelector->isEditor()) {
            $pathInfo = $event->getRequest()->getPathInfo();

            // can only create a CMS page, so the '_route' must be null
            $creatable = !$event->getRequest()->get('_route') && $this->decoratorStrategy->isRouteUriDecorable($pathInfo);

            if ($creatable) {
                $response = new Response($this->templating->render('@SonataPage/Page/create.html.twig', [
                    'pathInfo' => $pathInfo,
                    'site' => $this->siteSelector->retrieve(),
                    'creatable' => $creatable,
                ]), 404);

                $event->setResponse($response);
                $event->stopPropagation();

                return;
            }
        }

        if ($event->getException() instanceof InternalErrorException) {
            $this->handleInternalError($event);
        } else {
            $this->handleNativeError($event);
        }
    }
821030
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $request = $event->getRequest();
        $exception = $event->getException();
        if (!$exception instanceof HttpExceptionInterface || Zone::isBackend($request)) {
            return;
        }
        if ($exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
            return;
        }
        // If no zone is set, assume front-end as SELECT queries can leak unpublished records
        if (Zone::get($request) === null) {
            Zone::set($request, Zone::FRONTEND);
        }

        foreach ($this->notFoundPage as $item) {
            try {
                $this->renderNotFound($event, $item);

                return;
            } catch (LoaderError $e) {
                // Template not found, fall though to see if we can render a
                // record, failing that let the exception handler take over
            }

            $content = $this->storage->getContent($item, ['returnsingle' => true]);
            if ($content instanceof Content && !empty($content->id)) {
                $template = $this->templateChooser->record($content);
                $this->renderNotFound($event, $template, $content->getTemplateContext());

                return;
            }
        }

        $msg = sprintf(
            'No page could be shown, because the "notfound" setting "%s" in config.yml or theme.yml is not valid.',
            implode(', ', $this->notFoundPage)
        );
        $event->setException(new NotFoundHttpException($msg, $e));
    }
1238833
public function onConsoleException(ConsoleExceptionEvent $event)
    {
        $call = $this->callRepository->find($_REQUEST['call_id']);

        $call->setStatus(Call::STATUS_FAILED)
            ->setOutput($event->getException());

        $this->callRepository->update($call);

        $this->registerError($call);
    }
1184894
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        if (($exception = $event->getException()) instanceof RecordOriginModifiedException) {
            $content = array(
                "propertyPath" => "recordOrigin",
                "message"      => $exception->getMessage(),
            );

            // Set status code and content
            $response = new Response();
            $response
                ->setStatusCode($exception->getStatusCode())
                ->setContent(
                    $this->getSerializedContent($content)
                );

            $event->setResponse($response);
        }
    }
1003715
public function onException(ActionExceptionEvent $event)
    {
        $e = $event->getException();

        $message = sprintf(
            'API Exception: "%s" (%s) in file %s on line %d',
            $e->getMessage(),
            get_class($e),
            $e->getFile(),
            $e->getLine()
        );

        $this->logger->error($message);
    }
950978
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();

        if (!($event->getRequest())
            || ($this->matchAll === false && !$this->isApiException($exception))
        ) {
            return;
        }

        $data = [];

        if ($this->isApiException($exception)) {
            $exception = $this->exceptionManager->configure($exception);
        }

        $statusCode = $this->getStatusCode($exception);

        $data['error']['status']  = $statusCode;

        if ($code = $exception->getCode()) {
            $data['error']['code'] = $code;
        }

        $data['error']['message'] = $this->getMessage($exception);

        if ($this->isFlattenErrorException($exception)) {
            $data['error']['errors'] = $exception->getFlattenErrors();
        }

        if ($this->stackTrace) {
            $data['error']['stack_trace'] = $exception->getTrace();

            // Clean stacktrace to avoid circular reference or invalid type
            array_walk_recursive(
                $data['error']['stack_trace'],
                function(&$item) {
                    if (is_object($item)) {
                        $item = get_class($item);
                    } elseif (is_resource($item)) {
                        $item = get_resource_type($item);
                    }
                }
            );
        }

        $response = new JsonResponse($data, $statusCode, $this->getHeaders($exception));
        $event->setResponse($response);
    }
703783
@Override
    public void handleServerEvent(ISFSEvent event) throws SFSException {
        try {
            super.handleServerEvent(event);
        } catch(Exception e) {
            throw new SFSException(e);
        }
    }
448110
public function onConsoleException(ConsoleExceptionEvent $event)
    {
        if (!$this->auto) {
            return;
        }

        $exception = $event->getException();

        $meta = [
            'command' => [
                'name' => $event->getCommand()->getName(),
                'status' => $event->getExitCode(),
            ],
        ];

        $report = Report::fromPHPThrowable(
            $this->client->getConfig(),
            $exception
        );
        $report->setUnhandled(true);
        $report->setSeverityReason([
            'type' => 'unhandledExceptionMiddleware',
            'attributes' => [
                'framework' => 'Symfony',
            ],
        ]);
        $report->setMetaData($meta);

        $this->client->notify($report);
    }
688561
private function getPageNotFoundException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();

        if ($exception instanceof PageNotFoundException) {
            return $exception;
        }
        if ($exception->getPrevious() instanceof PageNotFoundException) {
            return $exception->getPrevious();
        }

        return null;
    }
1182429
public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($this->getException()) {
            $this->notifier->reportException($this->getException());
            $this->setException(null);
        }
    }
175466
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (!$attributes = RequestAttributesExtractor::extractAttributes($request)) {
            return;
        }

        $resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);

        $isGranted = $resourceMetadata->getOperationAttribute($attributes, 'access_control', null, true);

        if (null === $isGranted) {
            return;
        }

        $extraVariables = $request->attributes->all();
        $extraVariables['object'] = $request->attributes->get('data');
        $extraVariables['request'] = $request;

        if (!$this->resourceAccessChecker->isGranted($attributes['resource_class'], $isGranted, $extraVariables)) {
            throw new AccessDeniedException($resourceMetadata->getOperationAttribute($attributes, 'access_control_message', 'Access Denied.', true));
        }
    }
1002461
public function onException(GetResponseForExceptionEvent $event) {
    $exception = $event->getException();
    if (!($exception instanceof RouteException) || PHP_SAPI === 'cli') {
      return;
    }

    $handler = \Drupal::service('acm_exception.route_exception_handler');
    $redirect = $handler->getRedirect($exception);
    $event->setResponse(RedirectResponse::create($redirect, 302));
  }
608830
@Override
    public void handleServerEvent(ISFSEvent event) throws SFSException {
        User sfsUser = (User)event.getParameter(SFSEventParam.USER);
        ApiUser apiUser = (ApiUser) sfsUser.getProperty(APIKey.USER);
        if(apiUser.getBuddyProperties() != null) 
            updateBuddyProperties(sfsUser.getBuddyProperties(), 
                    apiUser.getBuddyProperties());
        removeAddedBuddies(sfsUser);
        super.handleServerEvent(event);
    }
1037989
public function onKernelException(GetResponseForExceptionEvent $e)
    {
        if (!$this->enabled) return;

        $req = $e->getRequest();
        $cfg = $req->attributes->get('_ac_web_service');

        //notify of generic API error, return early if a response gets set
        $e->getDispatcher()->dispatch(self::API_EXCEPTION, $e);
        if ($e->getResponse()) {
            return;
        }

        //handle exception body format
        $exception = $e->getException();
        $exceptionClass = get_class($exception);

        //preserve specific http exception codes and messages, otherwise it's 500
        $realHttpErrorCode = $outgoingHttpStatusCode = 500;
        $errorMessage = "Internal Server Error";
        if ($exception instanceof ServiceException) {
            $errorData = $exception->getData();
        }
        if ($exception instanceof HttpException) {
            $realHttpErrorCode = $outgoingHttpStatusCode = $exception->getStatusCode();
            $errorMessage = ($exception->getMessage()) ? $exception->getMessage() : Response::$statusTexts[$realHttpErrorCode];
        } elseif (isset($cfg['http_exception_map'][$exceptionClass])) {
            //check exception map for overrides
            $map = $cfg['http_exception_map'];
            $realHttpErrorCode = $outgoingHttpStatusCode = $map[$exceptionClass]['code'];
            $errorMessage =
                (isset($map[$exceptionClass]['message']))
                ? $map[$exceptionClass]['message']
                : Response::$statusTexts[$realHttpErrorCode];
        }

        //set generic error data
        if (!isset ($errorData)) {
            $errorData = [];
        }
        $errorData['response'] = [
            'code' => $realHttpErrorCode,
            'message' => $errorMessage,
        ];

        //inject exception data if configured to do so
        if ($cfg['include_exception_data']) {
            $errorData['exception'] = array(
                'class' => get_class($exception),
                'message' => $exception->getMessage(),
                'code' => $exception->getCode(),
                'file' => $exception->getFile(),
                'line' => $exception->getLine(),
                'trace' => explode("\n", ImprovedStackTrace::getTrace($exception)),
            );
        }

        //serialize error content into requested format, if format is not supported by the serializer, do json
        //TODO: consider support for exception template formats
        $format = isset($cfg['http_response_format']) ? $cfg['http_response_format'] : $cfg['default_response_format'];
        $format = (in_array($format, $this->serializableFormats)) ? $format : 'json';
        $content = $this->container->get('serializer')->serialize($errorData, $format);

        //check for code suppression
        if ($cfg['suppress_response_codes']) {
            $outgoingHttpStatusCode = 200;
        }

        //log the exception
        $logLevel = $realHttpErrorCode >= 500 ? 'error' : 'warning';
        $logMessage =
            "Caught exception (mapped to code $realHttpErrorCode), " .
            "response to client becomes HTTP $outgoingHttpStatusCode $errorMessage\n" .
            ImprovedStackTrace::getTrace($exception) . "\n---";
        $this->logger->log($logLevel, $logMessage);

        $headers = array_merge($cfg['additional_headers'], $this->formatHeaders[$format]);

        //set response
        $e->setResponse(new Response($content, $outgoingHttpStatusCode, $headers));
    }
574773
public function redirectTrailingSlashOrHtml(GetResponseForExceptionEvent $event)
    {
        if (!$event->getException() instanceof NotFoundHttpException) {
            return;
        }

        $request = $event->getRequest();

        /** @var RequestAttributes $attributes */
        $attributes = $request->attributes->get('_sulu');
        if (!$attributes) {
            return;
        }

        $prefix = $attributes->getAttribute('resourceLocatorPrefix');
        $resourceLocator = $attributes->getAttribute('resourceLocator');

        $route = '/' . trim($prefix . $resourceLocator, '/');
        if (!in_array($request->getRequestFormat(), ['htm', 'html'])
            || $route === $request->getPathInfo()
            || !$this->matchRoute($request->getSchemeAndHttpHost() . $route)
        ) {
            return;
        }

        $event->setResponse(new RedirectResponse($route, 301));
    }
617866
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        static $handling;

        if (true === $handling) {
            return;
        }

        $handling = true;

        $exception = $event->getException();
        $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));

        $request = $event->getRequest();

        // Only for debug
        if ($this->debug) {
            return;
        }

        // Not for xml http requests
        if ($request->isXmlHttpRequest()) {
            return;
        }

        // Only for phlexible tree nodes
        if (!$request->attributes->has('siterootUrl')) {
            $siteroot = $this->siterootRequestMatcher->matchRequest($request);
            if (!$siteroot) {
                return;
            }
            $request->attributes->set('siterootUrl', $siteroot->getDefaultUrl());
        }

        $exception = $event->getException();
        if ($exception instanceof HttpException) {
            $code = $exception->getStatusCode();
        } else {
            $code = $exception->getCode();
        }
        if (!in_array($code, array(401, 403, 404, 500))) {
            $code = 500;
        }

        $template = null;
        if ($this->twig->getLoader()->exists("::error/error-$code.html.twig")) {
            $template = "::error/error-$code.html.twig";
        } elseif ($this->twig->getLoader()->exists('::error/error.html.twig')) {
            $template = '::error/error.html.twig';
        }

        $tid = $siteroot->getSpecialTid($request->getLocale(), "error_$code");

        if (!$tid) {
            if (!$template) {
                return;
            }

            $content = $this->twig->render($template);
            $response = new Response($content, $code);

            $event->setResponse($response);

            return;
        }

        $treeNode = $this->treeManager->findByTreeId($tid)->get($tid);

        $request = $this->duplicateRequest($exception, $request, $tid, $treeNode, $template);

        try {
            $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
        } catch (\Exception $e) {
            $this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);

            $wrapper = $e;

            while ($prev = $wrapper->getPrevious()) {
                if ($exception === $wrapper = $prev) {
                    throw $e;
                }
            }

            $prev = new \ReflectionProperty('Exception', 'previous');
            $prev->setAccessible(true);
            $prev->setValue($wrapper, $exception);

            throw $e;
        }

        $event->setResponse($response);

        return;

        $configuration = $this->configurator->configure($request);
        if ($configuration->hasResponse()) {
            $event->setResponse($configuration->getResponse());

            return;
        }

        $data = $configuration->getVariables();
        $content = $this->twig->render($data['template'], $data);
        $response = new Response($content, $code);

        $event->setResponse($response);
    }