1 | <?php |
||
25 | class ExceptionWrapper |
||
26 | { |
||
27 | const RESPONSE_AUTHENTICATED_FAILED = 'AUTHENTICATED_FAILED'; |
||
28 | const RESPONSE_AUTHENTICATION_DENIED = 'AUTHENTICATION_DENIED'; |
||
29 | const RESPONSE_AUTHORIZATION_FAILED = 'AUTHORIZATION_FAILED'; |
||
30 | const RESPONSE_AUTHORISATION_FAILED = 'AUTHORISATION_FAILED'; |
||
31 | const RESPONSE_OUT = 'OUT'; |
||
32 | /** |
||
33 | * @var SerializerInterface |
||
34 | */ |
||
35 | private $serializer; |
||
36 | |||
37 | /** |
||
38 | * ExceptionWrapper constructor. |
||
39 | * |
||
40 | * @param SerializerInterface $serializer |
||
41 | */ |
||
42 | private function __construct(SerializerInterface $serializer) |
||
46 | |||
47 | public static function wrap(RequestException $exception, SerializerInterface $serializer) |
||
52 | |||
53 | /** |
||
54 | * @param RequestException $exception |
||
55 | * |
||
56 | * @return ApiException |
||
57 | */ |
||
58 | private function parseException(RequestException $exception) |
||
66 | |||
67 | /** |
||
68 | * @param RequestException $exception |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | private function create401ErrorMessage(RequestException $exception) |
||
79 | |||
80 | /** |
||
81 | * @param RequestInterface $request |
||
82 | * @param ResponseInterface $response |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | private function getExceptionMessage(RequestInterface $request, ResponseInterface $response) |
||
90 | |||
91 | /** |
||
92 | * @param RequestInterface $request |
||
93 | * |
||
94 | * @return null|string |
||
95 | */ |
||
96 | private function getExceptionMessageForRequest(RequestInterface $request) |
||
103 | |||
104 | /** |
||
105 | * @param RequestInterface $request |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | private function isRequestValid(RequestInterface $request) |
||
119 | |||
120 | /** |
||
121 | * @param ResponseInterface $response |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | private function getExceptionMessageForResponse(ResponseInterface $response) |
||
146 | } |
||
147 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: