/** * All exceptions are piped through this method from the framework workflow. This method will mask * any foreign exceptions with a "scent" of the native application's exception, so it can render * correctly when displayed on the error page. * @param Exception $proposedException The exception candidate that has been thrown. * @return View Object containing the error page. */ public function handleException(\Exception $proposedException, $httpCode = 500) { // Disable the error handler for test and CLI environment if (App::runningUnitTests() || App::runningInConsole()) { return; } // Detect AJAX request and use error 500 if (Request::ajax()) { return Response::make($proposedException->getMessage(), $httpCode); } // Clear the output buffer while (ob_get_level()) { ob_end_clean(); } // Friendly error pages are used if (Config::get('cms.customErrorPage')) { return $this->handleCustomError(); } // If the exception is already our brand, use it. if ($proposedException instanceof BaseException) { $exception = $proposedException; } elseif (static::$activeMask !== null) { $exception = static::$activeMask; $exception->setMask($proposedException); } else { $exception = new ApplicationException($proposedException->getMessage(), 0); $exception->setMask($proposedException); } // Ensure System view path is registered View::addNamespace('system', base_path() . '/modules/system/views'); return View::make('system::exception', ['exception' => $exception]); }