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
コード例 #1
0
ファイル: Session.php プロジェクト: SimonBaeumer/humhub
 /**
  * @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;
 }
コード例 #2
0
 protected function renderException($exception)
 {
     if (YII_ENV !== 'dev') {
         $this->sendErrorMessageToDevelopers($exception);
     }
     parent::renderException($exception);
 }
コード例 #3
0
ファイル: ErrorHandler.php プロジェクト: snivs/semanti
 /**
  * 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);
 }
コード例 #4
0
ファイル: ErrorHandler.php プロジェクト: cookyii/base
 /**
  * @inheritdoc
  */
 protected function convertExceptionToArray($exception)
 {
     $array = parent::convertExceptionToArray($exception);
     if ($exception instanceof ErrorsException) {
         $array['errors'] = $exception->errors;
     }
     return $array;
 }
コード例 #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);
 }
コード例 #6
0
ファイル: Redirect.php プロジェクト: thedollarsign/easyii
 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);
 }
コード例 #7
0
ファイル: HasRelatedProperties.php プロジェクト: Liv1020/cms
 /**
  * @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();
     }
 }
コード例 #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();
 }
コード例 #9
0
ファイル: DbSession.php プロジェクト: didwjdgks/yii2-info21c
 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;
 }
コード例 #10
0
ファイル: ErrorHandler.php プロジェクト: hughcube/yii2-web
 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);
     }
 }
コード例 #11
0
 /** @inheritdoc */
 public function behaviors()
 {
     return ArrayHelper::merge(parent::behaviors(), ['corsBehavior' => ['class' => CorsBehavior::class]]);
 }
コード例 #12
0
ファイル: DbSession.php プロジェクト: diandianxiyu/Yii2Api
 /**
  * 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;
 }
コード例 #13
0
ファイル: Sentry.php プロジェクト: jerryhsia/yii2-plugins
 public function handleException($exception)
 {
     $this->captureException($exception);
     parent::handleException($exception);
 }
コード例 #14
0
 /**
  * Handle Exception
  * @param \Exception $exception
  */
 public function handleException($exception)
 {
     $this->reportException($exception);
     parent::handleException($exception);
 }
コード例 #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);
 }