1
|
|
|
<?php |
2
|
|
|
namespace Phrest\Http; |
3
|
|
|
|
4
|
|
|
class Exception extends \Phrest\Exception |
5
|
|
|
{ |
6
|
|
|
private $error; |
7
|
|
|
|
8
|
1 |
|
public function __construct(int $statusCode, \Phrest\API\Error $error) |
9
|
|
|
{ |
10
|
1 |
|
parent::__construct($error->message(), $statusCode); |
11
|
1 |
|
$this->error = $error; |
12
|
1 |
|
} |
13
|
|
|
|
14
|
1 |
|
public function error() : \Phrest\API\Error { |
15
|
1 |
|
return $this->error; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
static public function BadRequest(\Phrest\API\Error $error) : Exception { |
19
|
|
|
return new Exception(\Phrest\Http\StatusCodes::BAD_REQUEST, $error); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
static public function Unauthorized(\Phrest\API\Error $error) : Exception { |
23
|
|
|
return new Exception(\Phrest\Http\StatusCodes::UNAUTHORIZED, $error); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
static public function PaymentRequired(\Phrest\API\Error $error) : Exception { |
27
|
|
|
return new Exception(\Phrest\Http\StatusCodes::PAYMENT_REQUIRED, $error); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
static public function Forbidden(\Phrest\API\Error $error) : Exception { |
31
|
|
|
return new Exception(\Phrest\Http\StatusCodes::FORBIDDEN, $error); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
static public function NotFound(\Phrest\API\Error $error) : Exception { |
35
|
|
|
return new Exception(\Phrest\Http\StatusCodes::NOT_FOUND, $error); |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
static public function MethodNotAllowed(\Phrest\API\Error $error) : Exception { |
39
|
1 |
|
return new Exception(\Phrest\Http\StatusCodes::METHOD_NOT_ALLOWED, $error); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
static public function NotAcceptable(\Phrest\API\Error $error) : Exception { |
43
|
|
|
return new Exception(\Phrest\Http\StatusCodes::NOT_ACCEPTABLE, $error); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
static public function ProxyAuthenticationRequired(\Phrest\API\Error $error) : Exception { |
47
|
|
|
return new Exception(\Phrest\Http\StatusCodes::PROXY_AUTHENTICATION_REQUIRED, $error); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
static public function RequestTimeout(\Phrest\API\Error $error) : Exception { |
51
|
|
|
return new Exception(\Phrest\Http\StatusCodes::REQUEST_TIMEOUT, $error); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
static public function Conflict(\Phrest\API\Error $error) : Exception { |
55
|
|
|
return new Exception(\Phrest\Http\StatusCodes::CONFLICT, $error); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
static public function Gone(\Phrest\API\Error $error) : Exception { |
59
|
|
|
return new Exception(\Phrest\Http\StatusCodes::GONE, $error); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
static public function LengthRequired(\Phrest\API\Error $error) : Exception { |
63
|
|
|
return new Exception(\Phrest\Http\StatusCodes::LENGTH_REQUIRED, $error); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
static public function PreconditionFailed(\Phrest\API\Error $error) : Exception { |
67
|
|
|
return new Exception(\Phrest\Http\StatusCodes::PRECONDITION_FAILED, $error); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
static public function RequestEntityTooLarge(\Phrest\API\Error $error) : Exception { |
71
|
|
|
return new Exception(\Phrest\Http\StatusCodes::REQUEST_ENTITY_TOO_LARGE, $error); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
static public function RequestUriTooLong(\Phrest\API\Error $error) : Exception { |
75
|
|
|
return new Exception(\Phrest\Http\StatusCodes::REQUEST_URI_TOO_LONG, $error); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
static public function UnsupportedMediaType(\Phrest\API\Error $error) : Exception { |
79
|
|
|
return new Exception(\Phrest\Http\StatusCodes::UNSUPPORTED_MEDIA_TYPE, $error); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
static public function RequestedRangeNotSatisfiable(\Phrest\API\Error $error) : Exception { |
83
|
|
|
return new Exception(\Phrest\Http\StatusCodes::REQUESTED_RANGE_NOT_SATISFIABLE, $error); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
static public function ExpectationFailed(\Phrest\API\Error $error) : Exception { |
87
|
|
|
return new Exception(\Phrest\Http\StatusCodes::EXPECTATION_FAILED, $error); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
static public function InternalServerError(\Phrest\API\Error $error) : Exception { |
91
|
|
|
return new Exception(\Phrest\Http\StatusCodes::INTERNAL_SERVER_ERROR, $error); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
static public function NotImplemented(\Phrest\API\Error $error) : Exception { |
95
|
|
|
return new Exception(\Phrest\Http\StatusCodes::NOT_IMPLEMENTED, $error); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
static public function BadGateway(\Phrest\API\Error $error) : Exception { |
99
|
|
|
return new Exception(\Phrest\Http\StatusCodes::BAD_GATEWAY, $error); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
static public function ServiceUnavailable(\Phrest\API\Error $error) : Exception { |
103
|
|
|
return new Exception(\Phrest\Http\StatusCodes::SERVICE_UNAVAILABLE, $error); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
static public function GatewayTimeout(\Phrest\API\Error $error) : Exception { |
107
|
|
|
return new Exception(\Phrest\Http\StatusCodes::GATEWAY_TIMEOUT, $error); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
static public function VersionNotSupported(\Phrest\API\Error $error) : Exception { |
111
|
|
|
return new Exception(\Phrest\Http\StatusCodes::VERSION_NOT_SUPPORTED, $error); |
112
|
|
|
} |
113
|
|
|
} |