1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\JsonRpc\Exception; |
4
|
|
|
|
5
|
|
|
class ResponseParseException extends \RuntimeException implements JsonRpcExceptionInterface |
6
|
|
|
{ |
7
|
|
|
/** @return static */ |
8
|
4 |
|
public static function noErrorOrResultPresent() |
9
|
|
|
{ |
10
|
4 |
|
return new static( |
11
|
4 |
|
sprintf( |
12
|
|
|
'Response received, but no error or result field present' |
13
|
4 |
|
) |
14
|
4 |
|
); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** @return static */ |
18
|
1 |
|
public static function bothErrorAndResultPresent() |
19
|
|
|
{ |
20
|
1 |
|
return new static( |
21
|
1 |
|
sprintf( |
22
|
|
|
'Response received, but both result and error fields are present' |
23
|
1 |
|
) |
24
|
1 |
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** @return static */ |
28
|
1 |
|
public static function noErrorCodePresent() |
29
|
|
|
{ |
30
|
1 |
|
return new static( |
31
|
1 |
|
sprintf( |
32
|
|
|
'Response received, error present, but no code field specified' |
33
|
1 |
|
) |
34
|
1 |
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @return static */ |
38
|
1 |
|
public static function noErrorMessagePresent() |
39
|
|
|
{ |
40
|
1 |
|
return new static( |
41
|
1 |
|
sprintf( |
42
|
|
|
'Response received, error present, but no message field specified' |
43
|
1 |
|
) |
44
|
1 |
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** @return static */ |
48
|
1 |
|
public static function noVersionSpecified() |
49
|
|
|
{ |
50
|
1 |
|
return new static( |
51
|
1 |
|
sprintf( |
52
|
|
|
'Response received, but no JSON-RPC version specified' |
53
|
1 |
|
) |
54
|
1 |
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** @return static */ |
58
|
1 |
|
public static function inconsistentVersionReceived() |
59
|
|
|
{ |
60
|
1 |
|
return new static( |
61
|
1 |
|
sprintf( |
62
|
|
|
'Response received, but response JSON-RPC version does not match client JSON-RPC version' |
63
|
1 |
|
) |
64
|
1 |
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** @return static */ |
68
|
|
|
public static function notAJsonResponse() |
69
|
|
|
{ |
70
|
|
|
return new static( |
71
|
|
|
sprintf( |
72
|
|
|
'Response received, but response body is not a valid JSON object' |
73
|
|
|
) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** @return static */ |
78
|
1 |
|
public static function noIdSpecified() |
79
|
|
|
{ |
80
|
1 |
|
return new static( |
81
|
1 |
|
sprintf( |
82
|
|
|
'Response received, but no JSON-RPC Request ID specified' |
83
|
1 |
|
) |
84
|
1 |
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return static |
89
|
|
|
*/ |
90
|
1 |
|
public static function errorIsNotAnObject() |
91
|
|
|
{ |
92
|
1 |
|
return new static( |
93
|
1 |
|
sprintf( |
94
|
|
|
'Response received, but error has invalid format' |
95
|
1 |
|
) |
96
|
1 |
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
2 |
|
public static function unexpectedType($path, $expected, $actual) |
100
|
|
|
{ |
101
|
2 |
|
return new static( |
102
|
2 |
|
sprintf( |
103
|
2 |
|
'Unexpected type for "%s": %s given, %s expected', |
104
|
2 |
|
$path, |
105
|
2 |
|
$actual, |
106
|
|
|
$expected |
107
|
2 |
|
) |
108
|
2 |
|
); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|