src/Moar/Net/Http/Request.php
public function validateResponse ($failIfNot200 = null) {
    if (null === $failIfNot200) {
      $failIfNot200 = $this->defaultFailIfNot200;
    }

    if (CURLE_OK != $this->responseCurlErr) {
      $exClazz = 'Moar\Net\Http\Exception';

      switch ($this->responseCurlErr) {
        case CURLE_UNSUPPORTED_PROTOCOL:
        case CURLE_URL_MALFORMAT:
          $exClazz = 'Moar\Net\Http\BadUrlException';
          break;

        case CURLE_COULDNT_RESOLVE_HOST:
          $exClazz = 'Moar\Net\Http\DnsFailureException';
          break;

        case CURLE_COULDNT_CONNECT:
          $exClazz = 'Moar\Net\Http\ConnectFailedException';
          break;

        case CURLE_HTTP_RETURNED_ERROR:
          $exClazz = 'Moar\Net\Http\StatusCodeException';
          break;

        case CURLE_OPERATION_TIMEDOUT:
          $exClazz = 'Moar\Net\Http\TimeoutException';
          break;

        case CURLE_PEER_FAILED_VERIFICATION:
        case CURLE_SSL_CACERT:
        case CURLE_SSL_CACERT_BADFILE:
        case CURLE_SSL_CERTPROBLEM:
        case CURLE_SSL_CERTPROBLEM:
        case CURLE_SSL_CIPHER:
        case CURLE_SSL_CONNECT_ERROR:
        case CURLE_SSL_CRL_BADFILE:
        case CURLE_SSL_ENGINE_INITFAILED:
        case CURLE_SSL_ENGINE_NOTFOUND:
        case CURLE_SSL_ENGINE_SETFAILED:
        case CURLE_SSL_ISSUER_ERROR:
        case CURLE_SSL_SHUTDOWN_FAILED:
        case CURLE_USE_SSL_FAILED:
          $exClazz = 'Moar\Net\Http\SslException';
          break;

      } //end switch
      throw new $exClazz(
          $this->responseCurlErrMessage, $this->responseCurlErr, $this);
    } //end if !ok

    if ($failIfNot200) {
      $code = $this->getResponseHttpCode();
      if ($code < 200 || $code > 299) {
        throw new StatusCodeException(
            "HTTP Error: ({$code}) from {$this->url}",
            CURLE_HTTP_RETURNED_ERROR, $this);
      }
    }
  }
public function validateResponse ($failIfNot200 = null) {
    if (null === $failIfNot200) {
      $failIfNot200 = $this->defaultFailIfNot200;
    }

    if (CURLE_OK != $this->responseCurlErr) {
      $exClazz = 'Moar\Net\Http\Exception';

      switch ($this->responseCurlErr) {
        case CURLE_UNSUPPORTED_PROTOCOL:
        case CURLE_URL_MALFORMAT:
          $exClazz = 'Moar\Net\Http\BadUrlException';
          break;

        case CURLE_COULDNT_RESOLVE_HOST:
          $exClazz = 'Moar\Net\Http\DnsFailureException';
          break;

        case CURLE_COULDNT_CONNECT:
          $exClazz = 'Moar\Net\Http\ConnectFailedException';
          break;

        case CURLE_HTTP_RETURNED_ERROR:
          $exClazz = 'Moar\Net\Http\StatusCodeException';
          break;

        case CURLE_OPERATION_TIMEDOUT:
          $exClazz = 'Moar\Net\Http\TimeoutException';
          break;

        case CURLE_PEER_FAILED_VERIFICATION:
        case CURLE_SSL_CACERT:
        case CURLE_SSL_CACERT_BADFILE:
        case CURLE_SSL_CERTPROBLEM:
        case CURLE_SSL_CERTPROBLEM:
        case CURLE_SSL_CIPHER:
        case CURLE_SSL_CONNECT_ERROR:
        case CURLE_SSL_CRL_BADFILE:
        case CURLE_SSL_ENGINE_INITFAILED:
        case CURLE_SSL_ENGINE_NOTFOUND:
        case CURLE_SSL_ENGINE_SETFAILED:
        case CURLE_SSL_ISSUER_ERROR:
        case CURLE_SSL_SHUTDOWN_FAILED:
        case CURLE_USE_SSL_FAILED:
          $exClazz = 'Moar\Net\Http\SslException';
          break;

      } //end switch
      throw new $exClazz(
          $this->responseCurlErrMessage, $this->responseCurlErr, $this);
    } //end if !ok

    if ($failIfNot200) {
      $code = $this->getResponseHttpCode();
      if ($code < 200 || $code > 299) {
        throw new StatusCodeException(
            "HTTP Error: ({$code}) from {$this->url}",
            CURLE_HTTP_RETURNED_ERROR, $this);
      }
    }
  }
public function validateResponse ( $ failIfNot200 = null ) { if ( null === $ failIfNot200 ) { $ failIfNot200 = $ this -> defaultFailIfNot200 ; } if ( CURLE_OK != $ this -> responseCurlErr ) { $ exClazz = 'Moar\Net\Http\Exception' ; switch ( $ this -> responseCurlErr ) { case CURLE_UNSUPPORTED_PROTOCOL : case CURLE_URL_MALFORMAT : $ exClazz = 'Moar\Net\Http\BadUrlException' ; break ; case CURLE_COULDNT_RESOLVE_HOST : $ exClazz = 'Moar\Net\Http\DnsFailureException' ; break ; case CURLE_COULDNT_CONNECT : $ exClazz = 'Moar\Net\Http\ConnectFailedException' ; break ; case CURLE_HTTP_RETURNED_ERROR : $ exClazz = 'Moar\Net\Http\StatusCodeException' ; break ; case CURLE_OPERATION_TIMEDOUT : $ exClazz = 'Moar\Net\Http\TimeoutException' ; break ; case CURLE_PEER_FAILED_VERIFICATION : case CURLE_SSL_CACERT : case CURLE_SSL_CACERT_BADFILE : case CURLE_SSL_CERTPROBLEM : case CURLE_SSL_CERTPROBLEM : case CURLE_SSL_CIPHER : case CURLE_SSL_CONNECT_ERROR : case CURLE_SSL_CRL_BADFILE : case CURLE_SSL_ENGINE_INITFAILED : case CURLE_SSL_ENGINE_NOTFOUND : case CURLE_SSL_ENGINE_SETFAILED : case CURLE_SSL_ISSUER_ERROR : case CURLE_SSL_SHUTDOWN_FAILED : case CURLE_USE_SSL_FAILED : $ exClazz = 'Moar\Net\Http\SslException' ; break ; } //end switch throw new $ exClazz ( $ this -> responseCurlErrMessage , $ this -> responseCurlErr , $ this ) ; } //end if !ok if ( $ failIfNot200 ) { $ code = $ this -> getResponseHttpCode ( ) ; if ( $ code < 200 || $ code > 299 ) { throw new StatusCodeException ( "HTTP Error: ({$code}) from {$this->url}" , CURLE_HTTP_RETURNED_ERROR , $ this ) ; } } }
Check the cURL response code and throw an exception if it is an error.
@param bool $failIfNot200 Throw an exception if a non-200 status was sent?
@return void
@throws Exception On cURL failure
Check the cURL response code and throw an exception if it is an error .