Skip to content

Commit 4bdb66e

Browse files
authored
Merge pull request #511 from hack-a-chain-software/error-to-warn
refactor: use console.warn instead of console.error in catch blocks of KDA-USD price update workflow and node/statistics cache
2 parents 1ce6f2e + 1923ca0 commit 4bdb66e

File tree

5 files changed

+27
-33
lines changed

5 files changed

+27
-33
lines changed

indexer/src/cache/init.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ 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',
81-
err,
82-
);
79+
console.error('[WARN][CACHE][DB] Failed to get hash rate and total difficulty', err);
8380
}
8481
}
8582

@@ -94,7 +91,7 @@ export default async function initCache(context: ResolverContext) {
9491
const networkStatistics = await networkRepository.getNetworkStatistics();
9592
MEMORY_CACHE.set(NETWORK_STATISTICS_KEY, networkStatistics);
9693
} catch (err) {
97-
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get network statistics', err);
94+
console.error('[WARN][CACHE][DB] Failed to get network statistics', err);
9895
}
9996
}
10097

@@ -109,23 +106,20 @@ export default async function initCache(context: ResolverContext) {
109106
const nodeInfo = await networkRepository.getNodeInfo();
110107
MEMORY_CACHE.set(NODE_INFO_KEY, nodeInfo);
111108
} catch (err) {
112-
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get node info', err);
109+
console.error('[WARN][CACHE][DB] Failed to get node info', err);
113110
}
114111
}
115112

116113
/**
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.
114+
* Fetches and caches information about number of blocks, transactions,
115+
* and total gas used in each chain.
121116
*/
122-
123117
async function getCountersOfEachChain() {
124118
try {
125119
const counters = await networkRepository.getCountersOfEachChain();
126120
MEMORY_CACHE.set(COUNTERS_OF_EACH_CHAIN_KEY, counters);
127121
} catch (err) {
128-
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get counters of each chain', err);
122+
console.error('[WARN][CACHE][DB] Failed to get counters of each chain', err);
129123
}
130124
}
131125

indexer/src/kadena-server/server.ts

Lines changed: 1 addition & 2 deletions
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,
@@ -520,7 +519,7 @@ export async function startGraphqlServer() {
520519
// Capture heap snapshot at 1GB memory threshold
521520
if (mem.heapUsed > 1 * 1024 * 1024 * 1024) {
522521
const filename = `/snapshots/indexer-heap-1GB-${Date.now()}.heapsnapshot`;
523-
console.warn(`[WARN][MEMORY] 1GB threshold reached! Capturing heap snapshot: ${filename}`);
522+
console.error(`[WARN][MEMORY] 1GB threshold reached! Capturing heap snapshot: ${filename}`);
524523
heapdump.writeSnapshot(filename);
525524
}
526525
};

indexer/src/services/monitoring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function initializeErrorMonitoring(): void {
7272
]
7373
.filter(Boolean)
7474
.join(', ');
75-
console.warn(`[WARN][MONITORING] Monitoring not initialized. Missing env: ${missing}`);
75+
console.error(`[WARN][MONITORING][ENV] Monitoring not initialized. Missing env: ${missing}`);
7676
return; // Monitoring disabled; keep local logging only
7777
}
7878

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.error('[WARN][INT][INT_API] 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
*

0 commit comments

Comments
 (0)