Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix(balances): Log an error and return the error message on failed ba…
Browse files Browse the repository at this point in the history
…lance fetcher invocation (#393)
  • Loading branch information
immasandwich authored May 8, 2022
1 parent f81aa92 commit 84430e2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/balance/balance.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
import { Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
import { fromPairs } from 'lodash';

import { BalanceFetcherRegistry } from './balance-fetcher.registry';
import { GetBalancesQuery } from './dto/get-balances-query.dto';

@Injectable()
export class BalanceService {
private logger = new Logger(BalanceService.name);

constructor(@Inject(BalanceFetcherRegistry) private readonly balanceFetcherRegistry: BalanceFetcherRegistry) {}

async getBalances({ appId, addresses, network }: GetBalancesQuery & { appId: string }) {
Expand All @@ -16,7 +18,10 @@ export class BalanceService {
fetcher
.getBalances(address)
.then(balance => [address, balance])
.catch(e => [address, { error: e }]),
.catch(e => {
this.logger.error(`Failed to fetch balance for ${appId} on network ${network}: ${e.stack}`);
return [address, { error: e.message }];
}),
),
);

Expand Down

0 comments on commit 84430e2

Please sign in to comment.