コード例 #1
0
 /**
  * Create a SPException from a TransferException
  *
  * @static
  * @access  public
  * @param   TransferException $e
  * @return  SPException
  */
 public static function fromTransferException(TransferException $e)
 {
     if ($e instanceof ParseException) {
         return new static('Could not parse response body as JSON', 0, $e);
     }
     if ($e instanceof RequestException) {
         $message = $e->getMessage();
         $code = $e->getCode();
         $matches = [];
         // if it's a cURL error, throw an exception with a more meaningful error
         if (preg_match('/^cURL error (?<code>\\d+): (?<message>.*)$/', $message, $matches)) {
             switch ($matches['code']) {
                 case 4:
                     // error triggered when libcURL doesn't support a protocol
                     $message = $matches['message'] . ' Hint: Check which SSL/TLS protocols your build of libcURL supports';
                     break;
                 case 35:
                     // this may happen when the SSLv2 or SSLv3 handshake fails
                     $message = $matches['message'] . ' Hint: Handshake failed. If supported, try using CURL_SSLVERSION_TLSv1_0';
                     break;
                 case 56:
                     // this can happen for several reasons
                     $message = $matches['message'] . ' Hint: Refer to the Troubleshooting.md document';
                     break;
                 default:
                     $message = $matches['message'];
                     break;
             }
             $code = $matches['code'];
         }
         return new static('Unable to make HTTP request: ' . $message, $code, $e);
     }
     return new static('Unable to make HTTP request', 0, $e);
 }
コード例 #2
0
 /**
  * @param $e
  */
 private function handleTransferException(TransferException $e)
 {
     throw new SystemException($e->getMessage(), $e->getCode(), $e);
 }