Exemplo n.º 1
0
 /**
  * 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]);
 }
Exemplo n.º 2
0
 /**
  * Sets standard page variables in the case of a controller error.
  */
 public function handleError($exception)
 {
     $errorMessage = ApplicationException::getDetailedMessage($exception);
     $this->fatalError = $errorMessage;
     $this->vars['fatalError'] = $errorMessage;
 }
Exemplo n.º 3
0
 /**
  * Masks this exception with the details of the supplied. The error code for
  * this exception object will determine how the supplied exception is used.
  * Error 100: A general exception. Inherits \System\Classes\ExceptionBase::applyMask()
  * Error 200: Mask the exception as INI content.
  * Error 300: Mask the exception as PHP content.
  * Error 400: Mask the exception as Twig content.
  * @param \Exception $exception The exception to modify.
  * @return void
  */
 public function applyMask(Exception $exception)
 {
     if ($this->code == 100 || $this->processCompoundObject($exception) === false) {
         parent::applyMask($exception);
         return;
     }
 }
Exemplo n.º 4
0
 /**
  * Executes the page, layout, component and plugin AJAX handlers.
  * @return mixed Returns the AJAX Response object or null.
  */
 protected function execAjaxHandlers()
 {
     if ($handler = trim(Request::header('X_OCTOBER_REQUEST_HANDLER'))) {
         try {
             /*
              * Validate the handler name
              */
             if (!preg_match('/^(?:\\w+\\:{2})?on[A-Z]{1}[\\w+]*$/', $handler)) {
                 throw new CmsException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name' => $handler]));
             }
             /*
              * Validate the handler partial list
              */
             if ($partialList = trim(Request::header('X_OCTOBER_REQUEST_PARTIALS'))) {
                 $partialList = explode('&', $partialList);
                 foreach ($partialList as $partial) {
                     if (!preg_match('/^(?:\\w+\\:{2}|@)?[a-z0-9\\_\\-\\.\\/]+$/i', $partial)) {
                         throw new CmsException(Lang::get('cms::lang.partial.invalid_name', ['name' => $partial]));
                     }
                 }
             } else {
                 $partialList = [];
             }
             $responseContents = [];
             /*
              * Execute the handler
              */
             if (!($result = $this->runAjaxHandler($handler))) {
                 throw new CmsException(Lang::get('cms::lang.ajax_handler.not_found', ['name' => $handler]));
             }
             /*
              * If the handler returned an array, we should add it to output for rendering.
              * If it is a string, add it to the array with the key "result".
              */
             if (is_array($result)) {
                 $responseContents = array_merge($responseContents, $result);
             } elseif (is_string($result)) {
                 $responseContents['result'] = $result;
             }
             /*
              * Render partials and return the response as array that will be converted to JSON automatically.
              */
             foreach ($partialList as $partial) {
                 $responseContents[$partial] = $this->renderPartial($partial);
             }
             /*
              * If the handler returned a redirect, process it so framework.js knows to redirect
              * the browser and not the request!
              */
             if ($result instanceof RedirectResponse) {
                 $responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl();
             }
             return Response::make($responseContents, $this->statusCode);
         } catch (ValidationException $ex) {
             /*
              * Handle validation errors
              */
             $responseContents['X_OCTOBER_ERROR_FIELDS'] = $ex->getFields();
             $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $ex->getMessage();
             return Response::make($responseContents, 406);
         } catch (Exception $ex) {
             return Response::make(ApplicationException::getDetailedMessage($ex), 500);
         }
     }
     return null;
 }