Skip to content

Commit c9cbfab

Browse files
committed
Improved error handling - passing original error to the response now.
1 parent 8c413fd commit c9cbfab

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Action.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,17 @@ public function executeRequest($request) {
136136
}
137137
catch (\Exception $exception) {
138138
if ($exception instanceof InvalidRouteException) {
139-
$result = new JsonRpcException($request->id, 'Method not found: ' . $route . '.', JSON_RPC_ERROR_METHOD_NOT_FOUND);
140-
return $result;
139+
$result = new JsonRpcException($request->id, 'Method not found: ' . $route . '.',
140+
JSON_RPC_ERROR_METHOD_NOT_FOUND, $exception);
141141
}
142142
else if ($exception instanceof JsonRpcException) {
143-
return $exception;
143+
$result = $exception;
144144
}
145145
else {
146-
$result = new JsonRpcException($request->id, 'Internal error.', JSON_RPC_ERROR_INTERNAL);
147-
return $result;
146+
$result = new JsonRpcException($request->id, 'Internal error.', JSON_RPC_ERROR_INTERNAL, $exception);
148147
}
148+
149+
return $result;
149150
}
150151
}
151152

JsonRpcException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
class JsonRpcException extends \yii\base\Exception {
1212

13-
public function __construct($id, $message = "", $code = 0, \Throwable $previous = null)
13+
public function __construct($id, $message = "", $code = 0, $previous = null)
1414
{
1515
parent::__construct($message, $code, $previous);
1616
$this->id = $id;

0 commit comments

Comments
 (0)