public function unhandled(Request $request, Exception $exception)
    {
        $debug = false;
        if (function_exists('config')) { // without a hard dependency on the entire laravel framework this is the only way to check for debug
            $debug = config('app.debug');
        } elseif (function_exists('env')) {
            $debug = env('APP_DEBUG');
        }

        if ($debug == true) {
            $whoops = new \Whoops\Run;
            if ($request->wantsJson()) {
                $whoops->pushHandler(new JsonResponseHandler);
            } else {
                $whoops->pushHandler(new PrettyPageHandler);
            }

            return new Response(
                $whoops->handleException($exception),
                500
            );
        }

        return parent::render($request, $exception);
    }