Skip to content

Commit 6ac73d3

Browse files
committed
fix critical bag of connectors
1 parent 24887ea commit 6ac73d3

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

Connectors/Http/HttpConnectorAbstract.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,18 @@ public function getNextId()
147147
* @param int $try_number Try number of getting answer from api
148148
*
149149
* @return array|object
150+
* @throws ConnectionException
150151
* @throws ConnectionFailureException
151152
*/
152153
public function doRequest($apiName, array $data, $answerFormat = self::ANSWER_FORMAT_ARRAY, $try_number = 1)
153154
{
154155
try {
155-
$data = [
156-
'jsonrpc' => '2.0',
157-
'id' => 1,
158-
'method' => 'call',
159-
'params' => [
160-
$apiName,
161-
$data['method'],
162-
$data['params']
163-
]
164-
];
165156
$connection = $this->getConnection();
166-
$answer['result'] = $connection->execute($data['method'], $data['params']);
157+
$answer['result'] = $connection->execute('call', $data['params']);
158+
159+
if (isset($answer['error'])) {
160+
throw new ConnectionFailureException('got error in answer: ' . $answer['error']['code'] . ' ' . $answer['error']['message']);
161+
}
167162

168163
} catch (ConnectionFailureException $e) {
169164

Connectors/WebSocket/GolosWSConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ class GolosWSConnector extends WSConnectorAbstract
1515
*
1616
* @var string
1717
*/
18-
protected $nodeURL = 'wss://ws.golos.io';
18+
protected $nodeURL = 'wss://ws17.golos.blog';
1919
}

Connectors/WebSocket/WSConnectorAbstract.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function getNextId()
152152
public function doRequest($apiName, array $data, $answerFormat = self::ANSWER_FORMAT_ARRAY, $try_number = 1)
153153
{
154154
$requestId = $this->getNextId();
155-
$data = [
155+
$requestData = [
156156
'jsonrpc' => '2.0',
157157
'id' => $requestId,
158158
'method' => 'call',
@@ -164,19 +164,22 @@ public function doRequest($apiName, array $data, $answerFormat = self::ANSWER_FO
164164
];
165165
try {
166166
$connection = $this->getConnection();
167-
$connection->send(json_encode($data, JSON_UNESCAPED_UNICODE));
167+
$connection->send(json_encode($requestData, JSON_UNESCAPED_UNICODE));
168168

169169
$answerRaw = $connection->receive();
170170
$answer = json_decode($answerRaw, self::ANSWER_FORMAT_ARRAY === $answerFormat);
171171

172+
if (isset($answer['error'])) {
173+
throw new ConnectionException('got error in answer: ' . $answer['error']['code'] . ' ' . $answer['error']['message']);
174+
}
172175
//check that answer has the same id or id from previous tries, else it is answer from other request
173176
if (self::ANSWER_FORMAT_ARRAY === $answerFormat) {
174177
$answerId = $answer['id'];
175178
} elseif (self::ANSWER_FORMAT_OBJECT === $answerFormat) {
176179
$answerId = $answer->id;
177180
}
178181
if ($requestId - $answerId > ($try_number - 1)) {
179-
throw new ConnectionException('get answer from old request');
182+
throw new ConnectionException('got answer from old request');
180183
}
181184

182185

0 commit comments

Comments
 (0)