This repository was archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHttpException.php
256 lines (223 loc) · 4.48 KB
/
HttpException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
namespace Fuzz\HttpException;
use Fuzz\HttpException\Contracts\HttpExceptionInterface;
use RuntimeException;
class HttpException extends RuntimeException implements HttpExceptionInterface
{
/**
* HTTP Status code.
*
* @var int
*/
protected $statusCode;
/**
* Http headers to pass to the response.
*
* @var array
*/
protected $httpHeaders;
/**
* An error code.
*
* @var string
*/
protected $error;
/**
* The error description.
*
* @var string
*/
protected $errorDescription;
/**
* Error data that an application can use to run logic.
*
* @var array|string|null
*/
protected $errorData;
/**
* An error title that can be presented to the user.
*
* @var string
*/
protected $userTitle;
/**
* A user friendly error message.
*
* If it is an array, the keys will be the field names, and the value the error for those fields.
*
* @var array|string|null
*/
protected $userMessage;
/**
* HttpException constructor.
*
* @param int $statusCode
* @param array $httpHeaders
* @param string $error
* @param string $errorDescription
* @param array $errorData
* @param string $userTitle
* @param string $userMessage
* @param \Exception|null $previous
*/
public function __construct(int $statusCode = null, string $error = null, string $errorDescription = null, $errorData = [], string $userTitle = null, $userMessage = null, array $httpHeaders = [], \Exception $previous = null)
{
$this->statusCode = $statusCode ?? 500;
$this->error = $error ?? 'internal_server_error';
$this->errorDescription = $errorDescription ?? 'Internal Server Error';
$this->errorData = $errorData;
$this->userTitle = $userTitle ?? 'Ooops!!!';
$this->userMessage = $userMessage ?? 'Seems one of our developers unplugged the server again!';
$this->httpHeaders = $httpHeaders;
$originalMessage = $errorDescription;
$originalCode = $statusCode;
parent::__construct($originalMessage, $originalCode, $previous);
}
/**
* Get the HTTP status code.
*
* @return int
*/
public function getStatusCode(): int
{
return $this->statusCode;
}
/**
* Set the HTTP status code.
*
* @param int $statusCode
*
* @return HttpException
*/
public function setStatusCode(int $statusCode): HttpException
{
$this->statusCode = $statusCode;
return $this;
}
/**
* Return HTTP headers.
*
* @return array
*/
public function getHttpHeaders()
{
return $this->httpHeaders;
}
/**
* Set the HTTP headers.
*
* @param array $httpHeaders
*
* @return HttpException
*/
public function setHttpHeaders(array $httpHeaders): HttpException
{
$this->httpHeaders = $httpHeaders;
return $this;
}
/**
* Get the error code.
*
* @return string
*/
public function getError(): string
{
return $this->error;
}
/**
* Set the error code.
*
* @param string $error
*
* @return HttpException
*/
public function setError(string $error): HttpException
{
$this->error = $error;
return $this;
}
/**
* Get the error description.
*
* @return string
*/
public function getErrorDescription(): string
{
return $this->errorDescription;
}
/**
* Set the error description.
*
* @param string $errorDescription
*
* @return HttpException
*/
public function setErrorDescription(string $errorDescription): HttpException
{
$this->errorDescription = $errorDescription;
return $this;
}
/**
* Get error data.
*
* @return array|null|string
*/
public function getErrorData()
{
return $this->errorData;
}
/**
* Set error data.
*
* @param array|null|string $errorData
*
* @return HttpException
*/
public function setErrorData($errorData)
{
$this->errorData = $errorData;
return $this;
}
/**
* Get user title.
*
* @return string
*/
public function getUserTitle(): string
{
return $this->userTitle;
}
/**
* Set user title.
*
* @param string $userTitle
*
* @return HttpException
*/
public function setUserTitle(string $userTitle): HttpException
{
$this->userTitle = $userTitle;
return $this;
}
/**
* Get user message.
*
* @return array|null|string
*/
public function getUserMessage()
{
return $this->userMessage;
}
/**
* Set user message.
*
* @param array|null|string $userMessage
*
* @return HttpException
*/
public function setUserMessage($userMessage)
{
$this->userMessage = $userMessage;
return $this;
}
}