|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
4
|
|
|
* file that was distributed with this source code. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Nikita Vershinin <[email protected]> |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace OpenStackStorage\Exceptions; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Raised when status code >= 400. |
|
13
|
|
|
*/ |
|
14
|
|
|
class ResponseError extends Error |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Array of reason phrases and their corresponding status codes |
|
19
|
|
|
* |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected static $errorStatuses = array( |
|
23
|
|
|
400 => 'Bad Request', |
|
24
|
|
|
401 => 'Unauthorized', |
|
25
|
|
|
402 => 'Payment Required', |
|
26
|
|
|
403 => 'Forbidden', |
|
27
|
|
|
404 => 'Not Found', |
|
28
|
|
|
405 => 'Method Not Allowed', |
|
29
|
|
|
406 => 'Not Acceptable', |
|
30
|
|
|
407 => 'Proxy Authentication Required', |
|
31
|
|
|
408 => 'Request Timeout', |
|
32
|
|
|
409 => 'Conflict', |
|
33
|
|
|
410 => 'Gone', |
|
34
|
|
|
411 => 'Length Required', |
|
35
|
|
|
412 => 'Precondition Failed', |
|
36
|
|
|
413 => 'Request Entity Too Large', |
|
37
|
|
|
414 => 'Request-URI Too Long', |
|
38
|
|
|
415 => 'Unsupported Media Type', |
|
39
|
|
|
416 => 'Requested Range Not Satisfiable', |
|
40
|
|
|
417 => 'Expectation Failed', |
|
41
|
|
|
422 => 'Unprocessable Entity', |
|
42
|
|
|
423 => 'Locked', |
|
43
|
|
|
424 => 'Failed Dependancy', |
|
44
|
|
|
425 => 'Reserved for WebDAV advanced collections expired proposal', |
|
45
|
|
|
426 => 'Upgrade required', |
|
46
|
|
|
428 => 'Precondition Required', |
|
47
|
|
|
429 => 'Too Many Requests', |
|
48
|
|
|
431 => 'Request Header Fields Too Large', |
|
49
|
|
|
500 => 'Internal Server Error', |
|
50
|
|
|
501 => 'Not Implemented', |
|
51
|
|
|
502 => 'Bad Gateway', |
|
52
|
|
|
503 => 'Service Unavailable', |
|
53
|
|
|
504 => 'Gateway Timeout', |
|
54
|
|
|
505 => 'HTTP Version Not Supported', |
|
55
|
|
|
506 => 'Variant Also Negotiates (Experimental)', |
|
56
|
|
|
507 => 'Insufficient Storage', |
|
57
|
|
|
508 => 'Loop Detected', |
|
58
|
|
|
510 => 'Not Extended', |
|
59
|
|
|
511 => 'Network Authentication Required', |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* The class constructor. |
|
64
|
|
|
* |
|
65
|
|
|
* @param integer $code |
|
66
|
|
|
*/ |
|
67
|
|
|
public function __construct($code) |
|
68
|
|
|
{ |
|
69
|
|
|
parent::__construct(self::$errorStatuses[$code], $code); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public function __toString() |
|
78
|
|
|
{ |
|
79
|
|
|
return sprintf('%d: %s', $this->getCode(), $this->getMessage()); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|