|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package cellcote/laravel-proxify |
|
5
|
|
|
* @author Michele Andreoli <michi.andreoli[at]gmail.com> |
|
6
|
|
|
* @copyright Copyright (c) Michele Andreoli |
|
7
|
|
|
* @author Rik Schreurs <rik.schreurs[at]mail.com> |
|
8
|
|
|
* @copyright Copyright (c) Rik Schreurs |
|
9
|
|
|
* @license http://mit-license.org/ |
|
10
|
|
|
* @link https://github.com/cellcote/laravel-proxify |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Cellcote\LaravelProxify\Exceptions; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Exception class |
|
17
|
|
|
*/ |
|
18
|
|
|
class ProxyException extends \Exception { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The HTTP status code for this exception that should be sent in the response |
|
22
|
|
|
*/ |
|
23
|
|
|
public $httpStatusCode = 400; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* If true the server should redirect back to the client |
|
27
|
|
|
* @var boolean |
|
28
|
|
|
*/ |
|
29
|
|
|
public $serverShouldRedirect = false; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The exception type |
|
33
|
|
|
*/ |
|
34
|
|
|
public $errorType = ''; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Throw a new exception |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct($msg = 'An error occured') { |
|
40
|
|
|
parent::__construct($msg); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Should the server redirect back to the client? |
|
45
|
|
|
* @return bool |
|
46
|
|
|
*/ |
|
47
|
|
|
public function shouldRedirect() { |
|
48
|
|
|
return $this->serverShouldRedirect; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get all headers that have to be send with the error response |
|
53
|
|
|
* @return array Array with header values |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getHttpHeaders() { |
|
56
|
|
|
$headers = []; |
|
57
|
|
|
switch ($this->httpStatusCode) { |
|
58
|
|
|
case 401: |
|
59
|
|
|
$headers[] = 'HTTP/1.1 401 Unauthorized'; |
|
60
|
|
|
break; |
|
61
|
|
|
case 403: |
|
62
|
|
|
$headers[] = 'HTTP/1.1 403 Forbidden'; |
|
63
|
|
|
break; |
|
64
|
|
|
case 500: |
|
65
|
|
|
$headers[] = 'HTTP/1.1 500 Internal Server Error'; |
|
66
|
|
|
break; |
|
67
|
|
|
case 501: |
|
68
|
|
|
$headers[] = 'HTTP/1.1 501 Not Implemented'; |
|
69
|
|
|
break; |
|
70
|
|
|
case 400: |
|
71
|
|
|
default: |
|
72
|
|
|
$headers[] = 'HTTP/1.1 400 Bad Request'; |
|
73
|
|
|
break; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $headers; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|