ErrorHandler displays these errors using appropriate views based on the nature of the errors and the mode the application runs at. ErrorHandler is configured as an application component in Application by default. You can access that instance via Yii::$app->errorHandler. For more details and usage information on ErrorHandler, see the guide article on handling errors.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Author: Timur Ruziev (resurtm@gmail.com)
Inheritance: extends yii\base\ErrorHandler
Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function writeSession($id, $data)
 {
     // exception must be caught in session write handler
     // http://us.php.net/manual/en/function.session-set-save-handler.php
     try {
         $userId = new Expression('NULL');
         if (!Yii::$app->user->isGuest) {
             $userId = Yii::$app->user->id;
         }
         $expire = time() + $this->getTimeout();
         $query = new Query();
         $exists = $query->select(['id'])->from($this->sessionTable)->where(['id' => $id])->createCommand($this->db)->queryScalar();
         if ($exists === false) {
             $this->db->createCommand()->insert($this->sessionTable, ['id' => $id, 'data' => $data, 'expire' => $expire, 'user_id' => $userId])->execute();
         } else {
             $this->db->createCommand()->update($this->sessionTable, ['data' => $data, 'expire' => $expire, 'user_id' => $userId], ['id' => $id])->execute();
         }
     } catch (\Exception $e) {
         $exception = ErrorHandler::convertExceptionToString($e);
         // its too late to use Yii logging here
         error_log($exception);
         echo $exception;
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 protected function renderException($exception)
 {
     if (YII_ENV !== 'dev') {
         $this->sendErrorMessageToDevelopers($exception);
     }
     parent::renderException($exception);
 }
Exemplo n.º 3
0
 /**
  * Renders the exception.
  * @param \Exception $exception the exception to be rendered.
  */
 protected function renderException($exception)
 {
     // debug info ----------------------------------------------------------
     \common\helpers\AppDebug::dump(['method' => __METHOD__, 'line' => __LINE__, 'exception' => $this->htmlEncode($this->convertExceptionToString($exception)), 'module' => AppHelper::getModuleName(), 'controller' => AppHelper::getControllerName(), 'action' => AppHelper::getActionName(), 'route' => AppHelper::getRoute(), 'clientIp' => AppHelper::getClientIp()]);
     // ---------------------------------------------------------------------
     parent::renderException($exception);
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 protected function convertExceptionToArray($exception)
 {
     $array = parent::convertExceptionToArray($exception);
     if ($exception instanceof ErrorsException) {
         $array['errors'] = $exception->errors;
     }
     return $array;
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  * @param \Exception $exception
  */
 protected function renderException($exception)
 {
     parent::renderException($exception);
     $status_code = 0;
     if (Yii::$app->has('response')) {
         $status_code = Yii::$app->getResponse()->statusCode;
     }
     $this->saveErrorInfo($exception, $status_code);
 }
Exemplo n.º 6
0
 public function handleException($exception)
 {
     $redirectModel = SeoRedirects::find()->where(['old_url' => Yii::$app->request->url])->asArray()->one();
     if (!empty($redirectModel)) {
         $redirectStatus = $redirectModel['status'] == 302 ? 302 : 301;
         header("Location: " . $redirectModel['new_url'], true, $redirectStatus);
         exit;
     }
     parent::handleException($exception);
 }
Exemplo n.º 7
0
 /**
  * @return string
  */
 public function renderRelatedPropertiesForm($viewFile = '@skeeks/cms/views/blank-form')
 {
     try {
         return \Yii::$app->view->render($viewFile, ['modelHasRelatedProperties' => $this->owner]);
     } catch (\Exception $e) {
         ob_end_clean();
         ErrorHandler::convertExceptionToError($e);
         return 'Ошибка рендеринга формы: ' . $e->getMessage();
     }
 }
Exemplo n.º 8
0
 /**
  * Renders the exception.
  * @param \Exception $exception the exception to be rendered.
  */
 protected function renderException($exception)
 {
     if (!$exception instanceof JqException) {
         parent::renderException($exception);
         return;
     }
     if (\Yii::$app->has('response')) {
         $response = \Yii::$app->getResponse();
     } else {
         $response = new Response();
     }
     $response->setStatusCode(500);
     $response->data['message'] = $exception->getMessage();
     $response->send();
 }
Exemplo n.º 9
0
 public function writeSession($id, $data)
 {
     try {
         $query = new Query();
         $exists = $query->select(['session_id'])->from($this->sessionTable)->where(['session_id' => $id])->createCommand($this->db)->queryScalar();
         if ($exists !== false) {
             $this->db->createCommand()->update($this->sessionTable, ['modified' => time(), 'session_data' => $data], ['session_id' => $id])->execute();
         }
     } catch (\Exception $e) {
         $exception = \yii\web\ErrorHandler::convertExceptionToString($e);
         // its too late to use Yii logging here
         error_log($exception);
         echo $exception;
         return false;
     }
     return true;
 }
Exemplo n.º 10
0
 protected function renderException($exception)
 {
     if ($this->useErrorAction) {
         $result = Yii::$app->runAction($this->errorAction);
         /**
          * 任何以\yii\base\Response为基类的实例都当成相应组建的返回
          */
         if ($result instanceof \yii\base\Response) {
             $response = $result;
         } else {
             if (Yii::$app->has('response')) {
                 $response = Yii::$app->getResponse();
                 $response->isSent = false;
                 $response->stream = $response->data = $response->content = null;
             } else {
                 $response = new Response();
             }
             $response->data = $result;
         }
         $response->send();
     } else {
         return parent::renderException($exception);
     }
 }
Exemplo n.º 11
0
 /** @inheritdoc */
 public function behaviors()
 {
     return ArrayHelper::merge(parent::behaviors(), ['corsBehavior' => ['class' => CorsBehavior::class]]);
 }
Exemplo n.º 12
0
 /**
  * Session write handler.
  * Do not call this method directly.
  * @param string $id session ID
  * @param string $data session data
  * @return boolean whether session write is successful
  */
 public function writeSession($id, $data)
 {
     // exception must be caught in session write handler
     // http://us.php.net/manual/en/function.session-set-save-handler.php
     try {
         $query = new Query();
         $exists = $query->select(['id'])->from($this->sessionTable)->where(['id' => $id])->createCommand($this->db)->queryScalar();
         $fields = $this->composeFields($id, $data);
         if ($exists === false) {
             $this->db->createCommand()->insert($this->sessionTable, $fields)->execute();
         } else {
             unset($fields['id']);
             $this->db->createCommand()->update($this->sessionTable, $fields, ['id' => $id])->execute();
         }
     } catch (\Exception $e) {
         $exception = ErrorHandler::convertExceptionToString($e);
         // its too late to use Yii logging here
         error_log($exception);
         echo $exception;
         return false;
     }
     return true;
 }
Exemplo n.º 13
0
 public function handleException($exception)
 {
     $this->captureException($exception);
     parent::handleException($exception);
 }
Exemplo n.º 14
0
 /**
  * Handle Exception
  * @param \Exception $exception
  */
 public function handleException($exception)
 {
     $this->reportException($exception);
     parent::handleException($exception);
 }
Exemplo n.º 15
0
 /**
  * Logs the given exception
  * @param \Exception $exception the exception to be logged
  */
 public function logException($exception)
 {
     parent::logException($exception);
     \Yii::$app->atlas->logException($exception);
 }