Beispiel #1
0
 /**
  * Returns human-readable exception name
  * @param \Exception $exception
  * @return string human-readable exception name or null if it cannot be determined
  */
 public function getExceptionName($exception)
 {
     if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidParamException || $exception instanceof \yii\base\UnknownMethodException) {
         return $exception->getName();
     }
     return null;
 }
 /**
  * Converts an exception into a simple string.
  * @param \Exception $exception the exception being converted
  * @return string the string representation of the exception.
  */
 public static function convertExceptionToString($exception)
 {
     if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) {
         $message = "{$exception->getName()}: {$exception->getMessage()}";
     } elseif (YII_DEBUG) {
         if ($exception instanceof Exception) {
             $message = "Exception ({$exception->getName()})";
         } elseif ($exception instanceof MyErrorException) {
             $message = "{$exception->getName()}";
         } else {
             $message = 'Exception';
         }
         $message .= " '" . get_class($exception) . "' with message '{$exception->getMessage()}' \n\nin " . $exception->getFile() . ':' . $exception->getLine() . "\n\n" . "Stack trace:\n" . $exception->getTraceAsString();
     } else {
         $message = 'Error: ' . $exception->getMessage();
     }
     return $message;
 }
Beispiel #3
0
 /**
  * Renders the exception.
  *
  * Note: This implementation renders the message in plain text. For HTML or ANSI consoles you might override this
  * method.
  *
  * @param \Exception $exception The exception to be rendered.
  */
 protected function renderException($exception)
 {
     if ($this->myDebug) {
         if ($exception instanceof ErrorException) {
             $message = $exception->getName();
         } elseif ($exception instanceof NamedException) {
             $message = "Exception ({$exception->getName()})";
         } else {
             $message = 'Exception';
         }
         $message .= " '" . get_class($exception) . "'";
         $message .= ' with message ' . $exception->getMessage();
         $message .= "\n\n";
         $message .= "in " . $exception->getFile() . ':' . $exception->getLine() . "\n";
         $message .= "\n";
         $message .= "Stack trace:\n";
         $message .= $exception->getTraceAsString();
     } elseif ($exception instanceof NamedException) {
         $message = $exception->getName() . ': ' . $exception->getMessage();
     } else {
         $message = 'Error: ' . $exception->getMessage();
     }
     echo $message, "\n";
 }
Beispiel #4
0
 /**
  * Converts an exception into an array.
  * @param \Exception $exception the exception being converted
  * @return array the array representation of the exception.
  */
 protected function convertExceptionToArray($exception)
 {
     $array = ['error' => []];
     if ($exception instanceof HttpException) {
         if ($exception->params) {
             $array['error']['params'] = $exception->params;
         }
         if (isset(Application::$httpTypes[$exception->statusCode])) {
             $array['error']['type'] = Application::$httpTypes[$exception->statusCode];
         }
     }
     $array['error']['message'] = $exception->getMessage();
     if (empty($array['error']['type'])) {
         if ($exception instanceof HttpException) {
             $array['debug']['status'] = $exception->statusCode;
         }
         $name = 'Exception';
         if ($exception instanceof Exception || $exception instanceof ErrorException) {
             $name = $exception->getName();
         }
         $array['debug']['name'] = $name;
         $array['debug']['code'] = $exception->getCode();
         $array['debug']['type'] = get_class($exception);
         $array['debug']['file'] = $exception->getFile();
         $array['debug']['line'] = $exception->getLine();
         $array['debug']['stack-trace'] = explode("\n", $exception->getTraceAsString());
     }
     if (($prev = $exception->getPrevious()) !== null) {
         $array['previous'] = $this->convertExceptionToArray($prev);
     }
     return $array;
 }