1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of Guzzle HTTP JSON-RPC |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @see http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE |
11
|
|
|
* @link http://github.com/graze/guzzle-jsonrpc |
12
|
|
|
*/ |
13
|
|
|
namespace Graze\GuzzleHttp\JsonRpc\Exception; |
14
|
|
|
|
15
|
|
|
use Exception; |
16
|
|
|
use Graze\GuzzleHttp\JsonRpc\Message\RequestInterface; |
17
|
|
|
use Graze\GuzzleHttp\JsonRpc\Message\ResponseInterface; |
18
|
|
|
use GuzzleHttp\Message\RequestInterface as HttpRequestInterface; |
19
|
|
|
use GuzzleHttp\Message\ResponseInterface as HttpResponseInterface; |
20
|
|
|
use GuzzleHttp\Exception\RequestException as HttpRequestException; |
21
|
|
|
|
22
|
|
|
class RequestException extends HttpRequestException |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
* |
27
|
|
|
* @param HttpRequestInterface $request Request |
28
|
|
|
* @param HttpResponseInterface $response Response received |
|
|
|
|
29
|
|
|
* @param \Exception $previous Previous exception |
|
|
|
|
30
|
|
|
* |
31
|
|
|
* @return HttpRequestException |
32
|
|
|
*/ |
33
|
9 |
|
public static function create( |
34
|
|
|
HttpRequestInterface $request, |
35
|
|
|
HttpResponseInterface $response = null, |
36
|
|
|
Exception $previous = null |
37
|
|
|
) { |
38
|
9 |
|
if ($request instanceof RequestInterface && $response instanceof ResponseInterface) { |
39
|
9 |
|
static $clientErrorCodes = [-32600, -32601, -32602, -32700]; |
40
|
|
|
|
41
|
9 |
|
$errorCode = $response->getRpcErrorCode(); |
42
|
9 |
|
if (in_array($errorCode, $clientErrorCodes)) { |
43
|
4 |
|
$label = 'Client RPC error response'; |
44
|
4 |
|
$className = __NAMESPACE__ . '\\ClientException'; |
45
|
4 |
|
} else { |
46
|
5 |
|
$label = 'Server RPC error response'; |
47
|
5 |
|
$className = __NAMESPACE__ . '\\ServerException'; |
48
|
|
|
} |
49
|
|
|
|
50
|
9 |
|
$message = $label . ' [url] ' . $request->getUrl() |
51
|
9 |
|
. ' [method] ' . $request->getRpcMethod() |
52
|
9 |
|
. ' [error code] ' . $errorCode |
53
|
9 |
|
. ' [error message] ' . $response->getRpcErrorMessage(); |
54
|
|
|
|
55
|
9 |
|
return new $className($message, $request, $response, $previous); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return parent::create($request, $response, $previous); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.