Skip to content

Commit 0f15b7f

Browse files
committed
refactor: use console.warn instead of console.error in catch blocks of KDA-USD price update workflow and node/statistics cache
1 parent 1ce6f2e commit 0f15b7f

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

indexer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"@sentry/profiling-node": "^9.19.0",
2222
"@types/axios": "^0.14.4",
2323
"apollo-server-plugin-base": "^3.7.2",
24-
"axios": "^1.9.0",
2524
"commander": "^12.0.0",
2625
"cors": "^2.8.5",
2726
"dataloader": "^2.2.2",

indexer/src/cache/init.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export default async function initCache(context: ResolverContext) {
7676
};
7777
MEMORY_CACHE.set(HASH_RATE_AND_TOTAL_DIFFICULTY_KEY, newValue);
7878
} catch (err) {
79-
console.error(
80-
'[ERROR][CACHE][CONN_TIMEOUT] Failed to get hash rate and total difficulty',
79+
console.warn(
80+
'[WARN][CACHE][HASH_RATE_AND_TOTAL_DIFFICULTY] Failed to get hash rate and total difficulty',
8181
err,
8282
);
8383
}
@@ -94,7 +94,7 @@ export default async function initCache(context: ResolverContext) {
9494
const networkStatistics = await networkRepository.getNetworkStatistics();
9595
MEMORY_CACHE.set(NETWORK_STATISTICS_KEY, networkStatistics);
9696
} catch (err) {
97-
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get network statistics', err);
97+
console.warn('[WARN][CACHE][NETWORK_STATISTICS] Failed to get network statistics', err);
9898
}
9999
}
100100

@@ -109,23 +109,23 @@ export default async function initCache(context: ResolverContext) {
109109
const nodeInfo = await networkRepository.getNodeInfo();
110110
MEMORY_CACHE.set(NODE_INFO_KEY, nodeInfo);
111111
} catch (err) {
112-
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get node info', err);
112+
console.warn('[WARN][CACHE][NODE_INFO] Failed to get node info', err);
113113
}
114114
}
115115

116116
/**
117-
* Fetches and caches information about the blockchain node
118-
*
119-
* This includes node version, connectivity status, and other
120-
* node-specific information that helps monitor the node's health.
117+
* Fetches and caches information about number of blocks, transactions,
118+
* and total gas used in each chain.
121119
*/
122-
123120
async function getCountersOfEachChain() {
124121
try {
125122
const counters = await networkRepository.getCountersOfEachChain();
126123
MEMORY_CACHE.set(COUNTERS_OF_EACH_CHAIN_KEY, counters);
127124
} catch (err) {
128-
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get counters of each chain', err);
125+
console.warn(
126+
'[WARN][CACHE][COUNTERS_OF_EACH_CHAIN] Failed to get counters of each chain',
127+
err,
128+
);
129129
}
130130
}
131131

indexer/src/kadena-server/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
} from 'graphql';
4545

4646
import initCache from '../cache/init';
47-
import { getArrayEnvString } from '../utils/helpers';
4847
import {
4948
directiveEstimator,
5049
fieldExtensionsEstimator,

indexer/src/services/price/price-updater.service.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import axios from 'axios';
2-
31
import { PriceService } from './price.service';
42

53
export class PriceUpdaterService {
@@ -23,11 +21,26 @@ export class PriceUpdaterService {
2321

2422
private async updatePrice(): Promise<void> {
2523
try {
26-
const response = await axios.get(this.DIA_API_URL);
27-
const price = response.data.Price;
28-
this.priceService.setKdaUsdPrice(price);
24+
const response = await fetch(this.DIA_API_URL, {
25+
headers: {
26+
Accept: 'application/json',
27+
'User-Agent': 'node-fetch',
28+
},
29+
});
30+
31+
if (!response.ok) {
32+
throw new Error(`HTTP ${response.status} - ${response.statusText}`);
33+
}
34+
35+
const data = await response.json();
36+
37+
if (data?.Price === undefined) {
38+
throw new Error('Price field is missing in API response');
39+
}
40+
41+
this.priceService.setKdaUsdPrice(data.Price);
2942
} catch (error) {
30-
console.error('[ERROR][INT][INT_API] Failed to update KDA/USD price:', error);
43+
console.warn('[WARN][API][PRICE_UPDATER] Failed to update KDA/USD price:', error);
3144
}
3245
}
3346

indexer/src/utils/helpers.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ export function getRequiredEnvString(key: string): string {
4040
return value;
4141
}
4242

43-
/**
44-
* Retrieves an optional environment variable as a string array.
45-
* The environment variable is expected to be a comma-separated string.
46-
*
47-
* @param key - The name of the environment variable to retrieve.
48-
* @returns The value of the environment variable as a string array, or an empty array if the variable is not set.
49-
*/
50-
export function getArrayEnvString(key: string): string[] {
51-
const value = process.env[key] ?? '';
52-
return value.split(',').filter(item => item.trim() !== '');
53-
}
54-
5543
/**
5644
* Checks if a value is null or undefined.
5745
*

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3410,7 +3410,7 @@ auto-bind@~4.0.0:
34103410
resolved "https://registry.npmjs.org/auto-bind/-/auto-bind-4.0.0.tgz"
34113411
integrity sha512-Hdw8qdNiqdJ8LqT0iK0sVzkFbzg6fhnQqqfWhBDxcHZvU75+B+ayzTy8x+k5Ix0Y92XOhOUlx74ps+bA6BeYMQ==
34123412

3413-
axios@*, axios@^1.9.0:
3413+
axios@*:
34143414
version "1.9.0"
34153415
resolved "https://registry.yarnpkg.com/axios/-/axios-1.9.0.tgz#25534e3b72b54540077d33046f77e3b8d7081901"
34163416
integrity sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==

0 commit comments

Comments
 (0)