All exceptions thrown in HTTP_Request2 are instances of HTTP_Request2_Exception. Since release 2.0.0beta1, HTTP_Request2 tries to throw a specialized subclass of that class and provide an error code when possible.
Checking for exception subclass and error code can help your application identify transient failures (e.g. HTTP_Request2_MessageException with error code HTTP_Request2_Exception::TIMEOUT). You can also use this information to display a user friendly error message instead of displaying Exception message that is more programmer friendly.
The following HTTP_Request2_Exception subclasses are available:
Subclasses of HTTP_Request2_Exception can contain two error codes:
The following package error codes are currently used:
Constant | Meaning |
---|---|
HTTP_Request2_Exception::INVALID_ARGUMENT | An invalid argument was passed to a method. |
HTTP_Request2_Exception::MISSING_VALUE | Some required value was not available. |
HTTP_Request2_Exception::MISCONFIGURATION | Request cannot be processed due to errors in PHP configuration (e.g. trying to use disabled PHP extension). |
HTTP_Request2_Exception::READ_ERROR | Error reading the local file. |
Constant | Meaning |
---|---|
HTTP_Request2_Exception::MALFORMED_RESPONSE | Server returned a response that does not conform to HTTP protocol. This means that even status line of response message could not be parsed. |
HTTP_Request2_Exception::DECODE_ERROR | Failure decoding Content-Encoding or Transfer-Encoding of response. |
HTTP_Request2_Exception::TIMEOUT | Operation timed out. |
HTTP_Request2_Exception::TOO_MANY_REDIRECTS | Number of redirects exceeded 'max_redirects' configuration parameter. |
HTTP_Request2_Exception::NON_HTTP_REDIRECT | Redirect to a protocol other than http(s):// . |