Skip to content

Commit 78a8e1a

Browse files
authored
Update Controller.php
1 parent 015a399 commit 78a8e1a

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

Controller.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
namespace georgique\yii2\jsonrpc;
44

5+
use Yii;
6+
use yii\filters\ContentNegotiator;
7+
use yii\web\Response;
8+
9+
const JSON_RPC_ERROR_PARSE = -32700;
10+
const JSON_RPC_ERROR_REQUEST_INVALID = -32600;
11+
const JSON_RPC_ERROR_METHOD_NOT_FOUND = -32601;
12+
const JSON_RPC_ERROR_METHOD_PARAMS_INVALID = -32602;
13+
const JSON_RPC_ERROR_INTERNAL = -32603;
14+
515
class Controller extends \yii\web\Controller {
616

717
public function actions()
@@ -19,10 +29,23 @@ public function actions()
1929
public function behaviors()
2030
{
2131
return [
22-
'jsonRpcFilter' => [
23-
'class' => JsonRpcFilter::className(),
24-
],
32+
'contentNegotiator' => [
33+
'class' => ContentNegotiator::className(),
34+
'formats' => [
35+
'*' => Response::FORMAT_JSON,
36+
],
37+
]
2538
];
2639
}
2740

41+
public function beforeAction($action)
42+
{
43+
if ($action == 'index') {
44+
// Replace error handler, so error response is a correct JSON-RPC one
45+
Yii::$app->set('errorHandler', ['class' => ErrorHandler::className()]);
46+
}
47+
48+
return true;
49+
}
50+
2851
}

0 commit comments

Comments
 (0)