<commit_before><?php

namespace Nova\Foundation\Exceptions;

use Nova\Auth\Access\AuthorizationException;
use Nova\Auth\AuthenticationException;
use Nova\Container\Container;
use Nova\Database\ORM\ModelNotFoundException;
use Nova\Http\Exception\HttpResponseException;
use Nova\Http\Response as HttpResponse;
use Nova\Foundation\Contracts\ExceptionHandlerInterface;
use Nova\Support\Facades\Config;
use Nova\Support\Facades\Redirect;
use Nova\Support\Facades\Response;
use Nova\Validation\ValidationException;

use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

use Psr\Log\LoggerInterface;

use Exception;
use Throwable;


class Handler implements ExceptionHandlerInterface
{
	/**
	 * The container implementation.
	 *
	 * @var \Nova\Container\Container
	 */
	protected $container;

	/**
	 * A list of the exception types that should not be reported.
	 *
	 * @var array
	 */
	protected $dontReport = array();


	/**
	 * Create a new exception handler instance.
	 *
	 * @param  \Psr\Log\LoggerInterface  $log
	 * @return void
	 */
	public function __construct(Container $container)
	{
		$this->container = $container;
	}

	/**
	 * Report or log an exception.
	 *
	 * @param  \Exception  $e
	 * @return void
	 */
	public function report(Exception $e)
	{
		if ($this->shouldntReport($e)) {
			return;
		}

		if (method_exists($e, 'report')) {
			return $e->report();
		}

		try {
			$logger = $this->container->make(LoggerInterface::class);
		}
		catch (Exception $ex) {
			throw $e; // Throw the original exception
		}

		$logger->error($e);
	}

	/**
	 * Determine if the exception should be reported.
	 *
	 * @param  \Exception  $e
	 * @return bool
	 */
	public function shouldReport(Exception $e)
	{
		return ! $this->shouldntReport($e);
	}

	/**
	 * Determine if the exception should be reported.
	 *
	 * @param  \Exception  $e
	 * @return bool
	 */
	public function shouldntReport(Exception $e)
	{
		$dontReport = array_merge($this->dontReport, array(
			HttpResponseException::class
		));

		foreach ($this->dontReport as $type) {
			if ($e instanceof $type) {
				return true;
			}
		}

		return false;
	}

	/**
	 * Prepare exception for rendering.
	 *
	 * @param  \Exception  $e
	 * @return \Exception
	 */
	protected function prepareException(Exception $e)
	{
		if ($e instanceof ModelNotFoundException) {
			$e = new NotFoundHttpException($e->getMessage(), $e);
		} elseif ($e instanceof AuthorizationException) {
			$e = new HttpException(403, $e->getMessage());
		}

		return $e;
	}

	/**
	 * Render an exception into a response.
	 *
	 * @param  \Nova\Http\Request  $request
	 * @param  \Exception  $e
	 * @return \Nova\Http\Response
	 */
	public function render($request, Exception $e)
	{
		$e = $this->prepareException($e);

		if ($e instanceof HttpResponseException) {
			return $e->getResponse();
		} else if ($e instanceof AuthenticationException) {
			return $this->unauthenticated($request, $e);
		} else if ($e instanceof ValidationException) {
			return $this->convertValidationExceptionToResponse($e, $request);
		}<commit_msg>Small change<commit_after><?php

namespace Nova\Foundation\Exceptions;

use Nova\Auth\Access\AuthorizationException;
use Nova\Auth\AuthenticationException;
use Nova\Container\Container;
use Nova\Database\ORM\ModelNotFoundException;
use Nova\Http\Exception\HttpResponseException;
use Nova\Http\Response as HttpResponse;
use Nova\Foundation\Contracts\ExceptionHandlerInterface;
use Nova\Support\Facades\Config;
use Nova\Support\Facades\Redirect;
use Nova\Support\Facades\Response;
use Nova\Validation\ValidationException;

use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

use Psr\Log\LoggerInterface;

use Exception;
use Throwable;


class Handler implements ExceptionHandlerInterface
{
	/**
	 * The container implementation.
	 *
	 * @var \Nova\Container\Container
	 */
	protected $container;

	/**
	 * A list of the exception types that should not be reported.
	 *
	 * @var array
	 */
	protected $dontReport = array();


	/**
	 * Create a new exception handler instance.
	 *
	 * @param  \Psr\Log\LoggerInterface  $log
	 * @return void
	 */
	public function __construct(Container $container)
	{
		$this->container = $container;
	}

	/**
	 * Report or log an exception.
	 *
	 * @param  \Exception  $e
	 * @return void
	 */
	public function report(Exception $e)
	{
		if ($this->shouldntReport($e)) {
			return;
		}

		if (method_exists($e, 'report')) {
			return $e->report();
		}

		try {
			$logger = $this->container->make(LoggerInterface::class);
		}
		catch (Exception $ex) {
			throw $e; // Throw the original exception
		}

		$logger->error($e);
	}

	/**
	 * Determine if the exception should be reported.
	 *
	 * @param  \Exception  $e
	 * @return bool
	 */
	public function shouldReport(Exception $e)
	{
		return ! $this->shouldntReport($e);
	}

	/**
	 * Determine if the exception should be reported.
	 *
	 * @param  \Exception  $e
	 * @return bool
	 */
	public function shouldntReport(Exception $e)
	{
		$dontReport = array_merge($this->dontReport, array(
			HttpResponseException::class
		));

		foreach ($this->dontReport as $type) {
			if ($e instanceof $type) {
				return true;
			}
		}

		return false;
	}

	/**
	 * Prepare exception for rendering.
	 *
	 * @param  \Exception  $e
	 * @return \Exception
	 */
	protected function prepareException(Exception $e)
	{
		if ($e instanceof ModelNotFoundException) {
			$e = new NotFoundHttpException($e->getMessage(), $e);
		} else if ($e instanceof AuthorizationException) {
			$e = new HttpException(403, $e->getMessage());
		}

		return $e;
	}

	/**
	 * Render an exception into a response.
	 *
	 * @param  \Nova\Http\Request  $request
	 * @param  \Exception  $e
	 * @return \Nova\Http\Response
	 */
	public function render($request, Exception $e)
	{
		$e = $this->prepareException($e);

		if ($e instanceof HttpResponseException) {
			return $e->getResponse();
		} else if ($e instanceof AuthenticationException) {
			return $this->unauthenticated($request, $e);
		} else if ($e instanceof ValidationException) {
			return $this->convertValidationExceptionToResponse($e, $request);
		}
{'fraction_non_alphanumeric': 0.12455621301775148, 'fraction_numerical': 0.0008875739644970414, 'mean_word_length': 3.9028281363306743, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1994298', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2002, 'n_words': 510}