Handle errors gracefully.

This commit is contained in:
softsimon 2021-09-20 01:02:07 +04:00
parent 0d67bc36ee
commit f3c8e2134b
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -6,13 +6,15 @@ import { DB } from '../../database';
import logger from '../../logger';
class ElementsParser {
isRunning = false;
private isRunning = false;
constructor() { }
public async $parse() {
if (this.isRunning) {
return;
}
try {
this.isRunning = true;
const result = await bitcoinClient.getChainTips();
const tip = result[0].height;
@ -24,6 +26,10 @@ class ElementsParser {
await this.$saveLatestBlockToDatabase(block.height, block.time, block.hash);
}
this.isRunning = false;
} catch (e) {
this.isRunning = false;
throw new Error(e instanceof Error ? e.message : 'Error');
}
}
public async $getPegDataByMonth(): Promise<any> {