File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change 22
33namespace georgique \yii2 \jsonrpc ;
44
5+ /**
6+ * Class Exception
7+ * Basic exception class for handling JSON-RPC errors.
8+ * @author George Shestayev [email protected] 9+ * @package georgique\yii2\jsonrpc
10+ */
511class Exception extends \yii \base \Exception {
612
13+ /* @var int Used for identifying request in a batch */
14+ public $ id ;
15+
716 /**
817 * @return string the user-friendly name of this exception
918 */
1019 public function getName ()
1120 {
1221 switch ($ this ->code ) {
13- case 32700 :
22+ case JSON_RPC_ERROR_PARSE :
1423 return 'Parse Error ' ;
1524
16- case 32600 :
25+ case JSON_RPC_ERROR_REQUEST_INVALID :
1726 return 'Invalid Request ' ;
1827
19- case 32601 :
28+ case JSON_RPC_ERROR_METHOD_NOT_FOUND :
2029 return 'Method not found ' ;
2130
22- case 32602 :
31+ case JSON_RPC_ERROR_METHOD_PARAMS_INVALID :
2332 return 'Invalid params ' ;
2433
25- case 32603 :
34+ case JSON_RPC_ERROR_INTERNAL :
2635 return 'Internal error ' ;
2736
2837 default :
29- if ($ this ->statusCode > 32000 && $ this ->statusCode < 32099 ) {
38+ if ($ this ->code < - 32000 && $ this ->code > - 32099 ) {
3039 return 'Server error ' ;
3140 }
3241 else {
@@ -35,4 +44,14 @@ public function getName()
3544 }
3645 }
3746
47+ public function toJsonRpcFormat () {
48+ return [
49+ 'code ' => $ this ->getCode (),
50+ 'message ' => $ this ->getMessage (),
51+ 'data ' => [
52+ // TODO Include some useful data here
53+ ]
54+ ];
55+ }
56+
3857}
You can’t perform that action at this time.
0 commit comments