public static function factory($name, \Exception $exception)
 {
     $message = sprintf("%s could not be found. The API returned this HTTP response:\n\n%s", $name, (string) $exception->getResponse());
     $e = new self($message);
     $e->name = $name;
     $e->response = $exception->getResponse();
     $e->request = $exception->getRequest();
     return $e;
 }
示例#2
0
 /**
  * @param \Exception $exception
  * @return GuzzleRestException
  */
 public static function createFromException(\Exception $exception)
 {
     if ($exception instanceof BadResponseException && $exception->getResponse()) {
         $url = $exception->getRequest() ? (string) $exception->getRequest()->getUrl() : null;
         $result = GuzzleRestException::createFromResponse(new GuzzleRestResponse($exception->getResponse(), $url), null, $exception);
     } else {
         /** @var GuzzleRestException $result */
         $result = new static($exception->getMessage(), $exception->getCode(), $exception);
     }
     return $result;
 }
示例#3
0
文件: Panel.php 项目: noikiy/Curl
 /**
  * @param \Exception $e
  *
  * @return array
  */
 public static function renderException($e)
 {
     $click = function ($o, $c = TRUE) {
         return Dumper::toHtml($o, array('collapse' => $c));
     };
     $panel = array();
     if ($e instanceof Curl\FailedRequestException) {
         $panel['info'] = '<h3>Info</h3>' . $click($e->getInfo(), TRUE);
     }
     if ($e instanceof Curl\CurlException) {
         if ($e->getRequest()) {
             $panel['request'] = '<h3>Request</h3>' . $click($e->getRequest(), TRUE);
         }
         if ($e->getResponse()) {
             $panel['response'] = '<h3>Responses</h3>' . static::allResponses($e->getResponse());
         }
     }
     if (!empty($panel)) {
         return array('tab' => 'Curl', 'panel' => implode($panel));
     }
 }
示例#4
0
 /**
  * @param \Exception|\Throwable $e
  * @return array|NULL
  */
 public static function renderException($e = NULL)
 {
     if (!$e instanceof ExceptionInterface) {
         return NULL;
     }
     $panel = NULL;
     if ($e instanceof Elastica\Exception\ResponseException) {
         $panel .= '<h3>Request</h3>';
         $panel .= Dumper::toHtml($e->getRequest());
         $panel .= '<h3>Response</h3>';
         $panel .= Dumper::toHtml($e->getResponse());
     } elseif ($e instanceof Elastica\Exception\Bulk\ResponseException) {
         $panel .= '<h3>Failures</h3>';
         $panel .= Dumper::toHtml($e->getFailures());
     }
     /*elseif ($e->getQuery() !== NULL) {
     			$panel .= '<h3>Query</h3>'
     				. '<pre class="nette-dump"><span class="php-string">'
     				. $e->getQuery()->getQuery()
     				. '</span></pre>';
     		} */
     return $panel ? array('tab' => 'ElasticSearch', 'panel' => $panel) : NULL;
 }