3 * Exception classes for HTTP_Request2 package
\r
9 * Copyright (c) 2008-2012, Alexey Borzov <avb@php.net>
\r
10 * All rights reserved.
\r
12 * Redistribution and use in source and binary forms, with or without
\r
13 * modification, are permitted provided that the following conditions
\r
16 * * Redistributions of source code must retain the above copyright
\r
17 * notice, this list of conditions and the following disclaimer.
\r
18 * * Redistributions in binary form must reproduce the above copyright
\r
19 * notice, this list of conditions and the following disclaimer in the
\r
20 * documentation and/or other materials provided with the distribution.
\r
21 * * The names of the authors may not be used to endorse or promote products
\r
22 * derived from this software without specific prior written permission.
\r
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
\r
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
\r
26 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
\r
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
\r
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
\r
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
\r
32 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
37 * @package HTTP_Request2
\r
38 * @author Alexey Borzov <avb@php.net>
\r
39 * @license http://opensource.org/licenses/bsd-license.php New BSD License
\r
40 * @version SVN: $Id: Exception.php 324415 2012-03-21 10:50:50Z avb $
\r
41 * @link http://pear.php.net/package/HTTP_Request2
\r
45 * Base class for exceptions in PEAR
\r
47 require_once 'PEAR/Exception.php';
\r
50 * Base exception class for HTTP_Request2 package
\r
53 * @package HTTP_Request2
\r
54 * @author Alexey Borzov <avb@php.net>
\r
55 * @license http://opensource.org/licenses/bsd-license.php New BSD License
\r
56 * @version Release: 2.1.1
\r
57 * @link http://pear.php.net/package/HTTP_Request2
\r
58 * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=132
\r
60 class HTTP_Request2_Exception extends PEAR_Exception
\r
62 /** An invalid argument was passed to a method */
\r
63 const INVALID_ARGUMENT = 1;
\r
64 /** Some required value was not available */
\r
65 const MISSING_VALUE = 2;
\r
66 /** Request cannot be processed due to errors in PHP configuration */
\r
67 const MISCONFIGURATION = 3;
\r
68 /** Error reading the local file */
\r
69 const READ_ERROR = 4;
\r
71 /** Server returned a response that does not conform to HTTP protocol */
\r
72 const MALFORMED_RESPONSE = 10;
\r
73 /** Failure decoding Content-Encoding or Transfer-Encoding of response */
\r
74 const DECODE_ERROR = 20;
\r
75 /** Operation timed out */
\r
77 /** Number of redirects exceeded 'max_redirects' configuration parameter */
\r
78 const TOO_MANY_REDIRECTS = 40;
\r
79 /** Redirect to a protocol other than http(s):// */
\r
80 const NON_HTTP_REDIRECT = 50;
\r
86 private $_nativeCode;
\r
89 * Constructor, can set package error code and native error code
\r
91 * @param string $message exception message
\r
92 * @param int $code package error code, one of class constants
\r
93 * @param int $nativeCode error code from underlying PHP extension
\r
95 public function __construct($message = null, $code = null, $nativeCode = null)
\r
97 parent::__construct($message, $code);
\r
98 $this->_nativeCode = $nativeCode;
\r
102 * Returns error code produced by underlying PHP extension
\r
104 * For Socket Adapter this may contain error number returned by
\r
105 * stream_socket_client(), for Curl Adapter this will contain error number
\r
106 * returned by curl_errno()
\r
110 public function getNativeCode()
\r
112 return $this->_nativeCode;
\r
117 * Exception thrown in case of missing features
\r
120 * @package HTTP_Request2
\r
121 * @author Alexey Borzov <avb@php.net>
\r
122 * @license http://opensource.org/licenses/bsd-license.php New BSD License
\r
123 * @version Release: 2.1.1
\r
124 * @link http://pear.php.net/package/HTTP_Request2
\r
126 class HTTP_Request2_NotImplementedException extends HTTP_Request2_Exception
\r
131 * Exception that represents error in the program logic
\r
133 * This exception usually implies a programmer's error, like passing invalid
\r
134 * data to methods or trying to use PHP extensions that weren't installed or
\r
135 * enabled. Usually exceptions of this kind will be thrown before request even
\r
138 * The exception will usually contain a package error code.
\r
141 * @package HTTP_Request2
\r
142 * @author Alexey Borzov <avb@php.net>
\r
143 * @license http://opensource.org/licenses/bsd-license.php New BSD License
\r
144 * @version Release: 2.1.1
\r
145 * @link http://pear.php.net/package/HTTP_Request2
\r
147 class HTTP_Request2_LogicException extends HTTP_Request2_Exception
\r
152 * Exception thrown when connection to a web or proxy server fails
\r
154 * The exception will not contain a package error code, but will contain
\r
155 * native error code, as returned by stream_socket_client() or curl_errno().
\r
158 * @package HTTP_Request2
\r
159 * @author Alexey Borzov <avb@php.net>
\r
160 * @license http://opensource.org/licenses/bsd-license.php New BSD License
\r
161 * @version Release: 2.1.1
\r
162 * @link http://pear.php.net/package/HTTP_Request2
\r
164 class HTTP_Request2_ConnectionException extends HTTP_Request2_Exception
\r
169 * Exception thrown when sending or receiving HTTP message fails
\r
171 * The exception may contain both package error code and native error code.
\r
174 * @package HTTP_Request2
\r
175 * @author Alexey Borzov <avb@php.net>
\r
176 * @license http://opensource.org/licenses/bsd-license.php New BSD License
\r
177 * @version Release: 2.1.1
\r
178 * @link http://pear.php.net/package/HTTP_Request2
\r
180 class HTTP_Request2_MessageException extends HTTP_Request2_Exception
\r