<?php\r
/**\r
- * Exception class for HTTP_Request2 package\r
+ * Exception classes for HTTP_Request2 package\r
*\r
* PHP version 5\r
*\r
* LICENSE:\r
*\r
- * Copyright (c) 2008, 2009, Alexey Borzov <avb@php.net>\r
+ * Copyright (c) 2008-2011, Alexey Borzov <avb@php.net>\r
* All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or without\r
* @package HTTP_Request2\r
* @author Alexey Borzov <avb@php.net>\r
* @license http://opensource.org/licenses/bsd-license.php New BSD License\r
- * @version CVS: $Id: Exception.php 273003 2009-01-07 19:28:22Z avb $\r
+ * @version SVN: $Id: Exception.php 308629 2011-02-24 17:34:24Z avb $\r
* @link http://pear.php.net/package/HTTP_Request2\r
*/\r
\r
require_once 'PEAR/Exception.php';\r
\r
/**\r
- * Exception class for HTTP_Request2 package\r
- *\r
- * Such a class is required by the Exception RFC:\r
- * http://pear.php.net/pepr/pepr-proposal-show.php?id=132\r
+ * Base exception class for HTTP_Request2 package\r
*\r
* @category HTTP\r
* @package HTTP_Request2\r
- * @version Release: 0.4.1\r
+ * @version Release: 2.0.0RC1\r
+ * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132\r
*/\r
class HTTP_Request2_Exception extends PEAR_Exception\r
{\r
+ /** An invalid argument was passed to a method */\r
+ const INVALID_ARGUMENT = 1;\r
+ /** Some required value was not available */\r
+ const MISSING_VALUE = 2;\r
+ /** Request cannot be processed due to errors in PHP configuration */\r
+ const MISCONFIGURATION = 3;\r
+ /** Error reading the local file */\r
+ const READ_ERROR = 4;\r
+\r
+ /** Server returned a response that does not conform to HTTP protocol */\r
+ const MALFORMED_RESPONSE = 10;\r
+ /** Failure decoding Content-Encoding or Transfer-Encoding of response */\r
+ const DECODE_ERROR = 20;\r
+ /** Operation timed out */\r
+ const TIMEOUT = 30;\r
+ /** Number of redirects exceeded 'max_redirects' configuration parameter */\r
+ const TOO_MANY_REDIRECTS = 40;\r
+ /** Redirect to a protocol other than http(s):// */\r
+ const NON_HTTP_REDIRECT = 50;\r
+\r
+ /**\r
+ * Native error code\r
+ * @var int\r
+ */\r
+ private $_nativeCode;\r
+\r
+ /**\r
+ * Constructor, can set package error code and native error code\r
+ *\r
+ * @param string exception message\r
+ * @param int package error code, one of class constants\r
+ * @param int error code from underlying PHP extension\r
+ */\r
+ public function __construct($message = null, $code = null, $nativeCode = null)\r
+ {\r
+ parent::__construct($message, $code);\r
+ $this->_nativeCode = $nativeCode;\r
+ }\r
+\r
+ /**\r
+ * Returns error code produced by underlying PHP extension\r
+ *\r
+ * For Socket Adapter this may contain error number returned by\r
+ * stream_socket_client(), for Curl Adapter this will contain error number\r
+ * returned by curl_errno()\r
+ *\r
+ * @return integer\r
+ */\r
+ public function getNativeCode()\r
+ {\r
+ return $this->_nativeCode;\r
+ }\r
}\r
+\r
+/**\r
+ * Exception thrown in case of missing features\r
+ *\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @version Release: 2.0.0RC1\r
+ */\r
+class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception {}\r
+\r
+/**\r
+ * Exception that represents error in the program logic\r
+ *\r
+ * This exception usually implies a programmer's error, like passing invalid\r
+ * data to methods or trying to use PHP extensions that weren't installed or\r
+ * enabled. Usually exceptions of this kind will be thrown before request even\r
+ * starts.\r
+ *\r
+ * The exception will usually contain a package error code.\r
+ *\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @version Release: 2.0.0RC1\r
+ */\r
+class HTTP_Request2_LogicException extends HTTP_Request2_Exception {}\r
+\r
+/**\r
+ * Exception thrown when connection to a web or proxy server fails\r
+ *\r
+ * The exception will not contain a package error code, but will contain\r
+ * native error code, as returned by stream_socket_client() or curl_errno().\r
+ *\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @version Release: 2.0.0RC1\r
+ */\r
+class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception {}\r
+\r
+/**\r
+ * Exception thrown when sending or receiving HTTP message fails\r
+ *\r
+ * The exception may contain both package error code and native error code.\r
+ *\r
+ * @category HTTP\r
+ * @package HTTP_Request2\r
+ * @version Release: 2.0.0RC1\r
+ */\r
+class HTTP_Request2_MessageException extends HTTP_Request2_Exception {}\r
?>
\ No newline at end of file