Better error handling for accelerations update request
This commit is contained in:
parent
08a35b85a8
commit
b7c4cd43fc
@ -1,6 +1,7 @@
|
|||||||
import { query } from '../../utils/axios-query';
|
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
|
import logger from '../../logger';
|
||||||
import { BlockExtended, PoolTag } from '../../mempool.interfaces';
|
import { BlockExtended, PoolTag } from '../../mempool.interfaces';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
export interface Acceleration {
|
export interface Acceleration {
|
||||||
txid: string,
|
txid: string,
|
||||||
@ -9,10 +10,15 @@ export interface Acceleration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AccelerationApi {
|
class AccelerationApi {
|
||||||
public async $fetchAccelerations(): Promise<Acceleration[]> {
|
public async $fetchAccelerations(): Promise<Acceleration[] | null> {
|
||||||
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
|
if (config.MEMPOOL_SERVICES.ACCELERATIONS) {
|
||||||
const response = await query(`${config.MEMPOOL_SERVICES.API}/accelerator/accelerations`);
|
try {
|
||||||
return (response as Acceleration[]) || [];
|
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 {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user