<commit_before><?php
namespace Barryvanveen\Exceptions;

use Bugsnag;
use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Session\TokenMismatchException;
use Input;
use Meta;
use Redirect;
use Response;
use Session;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use View;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
    ];

    /**
     * Log exceptions to Bugsnag and write them to the log file.
     *
     * @param \Exception $e
     */
    public function report(Exception $e)
    {
        Bugsnag::setAppVersion(config('app.version'));

        parent::report($e);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Exception               $e
     *
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        // render exception if debugging is enabled
        if (config('app.debug')) {
            return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
        }

        // wrong csrf token
        if ($e instanceof TokenMismatchException) {
            Session::regenerateToken();

            $errors = [
                '_token' => [
                    trans('validation.token-mismatch'),
                ],
            ];

            return Redirect::back()->withInput(Input::except('_token'))->withErrors($errors);
        }

        // wrong login credentions
        if ($e instanceof InvalidLoginException) {
            sleep(3);

            $errors = [
                'password' => [
                    trans('validation.invalid-login'),
                ],
            ];

            return Redirect::back()->withInput(['email' => Input::get('email')])->withErrors($errors);
        }

        // route not found
        if ($e instanceof NotFoundHttpException) {
            Meta::title(trans('meta.pagetitle-404'));

            return Response::make(View::make('templates.404'), 404);
        }

        // model not found
        if ($e instanceof ModelNotFoundException) {
            Meta::title(trans('meta.pagetitle-404'));

            return Response::make(View::make('templates.404'), 404);
        }

        // not authorized to see this route
        if ($e instanceof MethodNotAllowedHttpException) {
            Meta::title(trans('meta.pagetitle-403'));

            return Response::make(View::make('templates.403'), 403);
        }

        // general error
        Meta::title(trans('meta.pagetitle-500'));

        return Response::make(View::make('templates.500'), 500);
    }
}
<commit_msg>add errorcodes to javascript variables available in DOM<commit_after><?php
namespace Barryvanveen\Exceptions;

use Bugsnag;
use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Session\TokenMismatchException;
use Input;
use JavaScript;
use Meta;
use Redirect;
use Response;
use Session;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use View;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
    ];

    /**
     * Log exceptions to Bugsnag and write them to the log file.
     *
     * @param \Exception $e
     */
    public function report(Exception $e)
    {
        Bugsnag::setAppVersion(config('app.version'));

        parent::report($e);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Exception               $e
     *
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        // render exception if debugging is enabled
        if (config('app.debug')) {
            return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
        }

        // wrong csrf token
        if ($e instanceof TokenMismatchException) {
            Session::regenerateToken();

            $errors = [
                '_token' => [
                    trans('validation.token-mismatch'),
                ],
            ];

            return Redirect::back()->withInput(Input::except('_token'))->withErrors($errors);
        }

        // wrong login credentions
        if ($e instanceof InvalidLoginException) {
            sleep(3);

            $errors = [
                'password' => [
                    trans('validation.invalid-login'),
                ],
            ];

            return Redirect::back()->withInput(['email' => Input::get('email')])->withErrors($errors);
        }

        // route not found
        if ($e instanceof NotFoundHttpException) {
            Meta::title(trans('meta.pagetitle-404'));

            JavaScript::put(array(
                'errorcode' => 404
            ));

            return Response::make(View::make('templates.404'), 404);
        }

        // model not found
        if ($e instanceof ModelNotFoundException) {
            Meta::title(trans('meta.pagetitle-404'));

            JavaScript::put(array(
                'errorcode' => 404
            ));

            return Response::make(View::make('templates.404'), 404);
        }

        // not authorized to see this route
        if ($e instanceof MethodNotAllowedHttpException) {
            Meta::title(trans('meta.pagetitle-403'));

            JavaScript::put(array(
                'errorcode' => 403
            ));

            return Response::make(View::make('templates.403'), 403);
        }

        // general error
        Meta::title(trans('meta.pagetitle-500'));

        JavaScript::put(array(
            'errorcode' => 500
        ));

        return Response::make(View::make('templates.500'), 500);
    }
}

{'fraction_non_alphanumeric': 0.12396298659859604, 'fraction_numerical': 0.01372048500319081, 'mean_word_length': 2.1003956478733925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '2069458', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1636, 'n_words': 361}