<commit_before><?php

/*
 * This file is part of the shopery/error-bundle package.
 *
 * Copyright (c) 2015 Shopery.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Shopery\Bundle\ErrorBundle\Listener;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;

/**
 * Class ExceptionListener
 *
 * @author <NAME> <<EMAIL>>
 */
class ExceptionListener
{
    /**
     * @var array
     */
    private $exceptions;

    /**
     * @param array $exceptions
     */
    public function __construct(array $exceptions)
    {
        $this->exceptions = $exceptions;
    }

    /**
     * @param GetResponseForExceptionEvent $event
     */
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        if ($exception instanceof HttpException) {
            return;
        }

        foreach ($this->exceptions as $className => $settings) {
            if (is_a($exception, $className)) {

                $code = $settings['code'];
                $message = $settings['expose_message']
                    ? $exception->getMessage()
                    : Response::$statusTexts[$code];

                throw new HttpException($code, $message, $exception);
            }
        }
    }
}<commit_msg>do not rethrow, but set exception in event<commit_after><?php

/*
 * This file is part of the shopery/error-bundle package.
 *
 * Copyright (c) 2015 Shopery.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Shopery\Bundle\ErrorBundle\Listener;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;

/**
 * Class ExceptionListener
 *
 * @author <NAME> <<EMAIL>>
 */
class ExceptionListener
{
    /**
     * @var array
     */
    private $exceptions;

    /**
     * @param array $exceptions
     */
    public function __construct(array $exceptions)
    {
        $this->exceptions = $exceptions;
    }

    /**
     * @param GetResponseForExceptionEvent $event
     */
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        if ($exception instanceof HttpException) {
            return;
        }

        $exception = $this->decorateException($exception);
        if ($exception) {
            $event->setException($exception);
        }
    }

    private function decorateException($exception)
    {
        foreach ($this->exceptions as $className => $settings) {
            if (is_a($exception, $className)) {

                $code = $settings['code'];
                $message = $settings['expose_message']
                    ? $exception->getMessage()
                    : Response::$statusTexts[$code];

                return new HttpException($code, $message, $exception);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.11465167135270228, 'fraction_numerical': 0.002499218994064355, 'mean_word_length': 2.4504310344827585, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '945349', 'n_tokens_mistral': 859, 'n_tokens_neox': 834, 'n_words': 201}