Better error handling for accelerations update request

This commit is contained in:
Mononaut 2023-12-06 12:09:46 +00:00
parent 08a35b85a8
commit b7c4cd43fc
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E

View File

@ -1,6 +1,7 @@
import { query } from '../../utils/axios-query';
import config from '../../config';
import logger from '../../logger';
import { BlockExtended, PoolTag } from '../../mempool.interfaces';
import axios from 'axios';
export interface Acceleration {
txid: string,
@ -9,10 +10,15 @@ export interface Acceleration {
}
class AccelerationApi {
public async $fetchAccelerations(): Promise<Acceleration[]> {
public async $fetchAccelerations(): Promise<Acceleration[] | null> {
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
const response = await query(`${config.MEMPOOL_SERVICES.API}/accelerator/accelerations`);
return (response as Acceleration[]) || [];
try {
const response = await axios.get(`${config.MEMPOOL_SERVICES.API}/accelerator/accelerations`, { responseType: 'json', timeout: 10000 });
return response.data as Acceleration[];
} catch (e) {
logger.warn('Failed to fetch current accelerations from the mempool services backend: ' + (e instanceof Error ? e.message : e));
return null;
}
} else {
return [];
}