Skip to content

Commit f66ba3a

Browse files
authored
v2.3.1 (#59)
* feat: export validator utils * chore: bump a version * fix(typescript): represent transaction id as a string (#52) * fix: remove preinstall npm script (#53) * fix: remove preinstall npm script * chore: bump a version * Fix/transaction query (#51) * chore(CHANGELOG): v2.3.0 * fix: health check bugs * fix: health check works only for one random node * fix(healthCheck): logging non existing extra attempt * fix(healthCheck): logging right amount of total nodes * fix(healthCheck): node failed with `undefined` status code * chore: fix grammar * chore: bump a version * docs: update changelog
1 parent 73309a6 commit f66ba3a

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [2.3.1] - 2024-04-26
4+
5+
### Fixed
6+
7+
- A bug when only one random node was checked
8+
- Log messages for health checks
9+
310
## [2.3.0] - 2024-03-01
411

512
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adamant-api",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "JavaScript API library for the ADAMANT Blockchain",
55
"keywords": [
66
"adm",

src/api/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,20 @@ export class AdamantApi extends NodeManager {
204204
return response.data;
205205
} catch (error) {
206206
if (error instanceof AxiosError) {
207-
const logMessage = `[ADAMANT js-api] Get-request: Request to ${url} failed with ${error
208-
.response?.status} status code, ${error}${
209-
error.response?.data
210-
? '. Message: ' + error.response.data.toString().trim()
211-
: ''
212-
}. Try ${retryNo} of ${maxRetries}.`;
207+
const {response} = error;
208+
209+
const nodeStatus = response?.status
210+
? `Request to ${url} failed with ${response.status} status code`
211+
: `Node ${url} hasn't returned its status`;
212+
213+
const logMessage = `[ADAMANT js-api] Get-request: ${nodeStatus}, ${error}${
214+
response?.data ? '. Message: ' + response.data.toString().trim() : ''
215+
}.`;
213216

214217
if (retryNo <= maxRetries) {
215-
logger.log(`${logMessage} Retrying…`);
218+
logger.log(
219+
`${logMessage} Try ${retryNo} of ${maxRetries}. Retrying…`
220+
);
216221

217222
await this.updateNodes();
218223
return this.request<T>(method, endpoint, data, retryNo + 1);

src/helpers/healthCheck.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ export class NodeManager {
116116

117117
const {length: activeNodesCount} = activeNodes;
118118
if (!activeNodesCount) {
119+
const totalNodesCount = this.options.nodes.length;
120+
119121
logger.error(
120-
`[ADAMANT js-api] Health check: All of ${activeNodesCount} nodes are unavailable. Check internet connection and nodes list in config.`
122+
`[ADAMANT js-api] Health check: All of ${totalNodesCount} nodes are unavailable. Check internet connection and nodes list in config.`
121123
);
122124
return;
123125
}
@@ -215,7 +217,7 @@ export class NodeManager {
215217
);
216218
}
217219

218-
async getNodeStatus(node: string) {
220+
async checkNode(node: string) {
219221
try {
220222
const {timeout} = this.options;
221223

@@ -239,13 +241,13 @@ export class NodeManager {
239241
for (const node of nodes) {
240242
const start = unixTimestamp();
241243

242-
const response = await this.getNodeStatus(node);
244+
const response = await this.checkNode(node);
243245

244246
const ping = unixTimestamp() - start;
245247

246248
if (!response.success) {
247249
this.logger.log(
248-
`[ADAMANT js-api] Health check: Node ${node} haven't returned its status`
250+
`[ADAMANT js-api] Health check: Node ${node} hasn't returned its status`
249251
);
250252
continue;
251253
}

0 commit comments

Comments
 (0)