Skip to content

Commit d729ef8

Browse files
committed
update error handling in ExchangeApiKeysController and StakingService to return null and zero respectively
1 parent 06e6916 commit d729ef8

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

packages/apps/reputation-oracle/server/src/modules/exchange-api-keys/exchange-api-keys.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ export class ExchangeApiKeysController {
5454
@Get('/')
5555
async retrieveEnrolledApiKeys(
5656
@Req() request: RequestWithUser,
57-
): Promise<EnrolledApiKeyDto> {
57+
): Promise<EnrolledApiKeyDto | null> {
5858
const userId = request.user.id;
5959

6060
const apiKey = await this.exchangeApiKeysService.retrieve(userId);
6161
if (!apiKey) {
62-
throw new ExchangeApiKeyNotFoundError(userId);
62+
return null;
6363
}
6464

6565
return {

packages/apps/reputation-oracle/server/src/modules/staking/staking.service.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import { SupportedExchange } from '@/common/constants';
1010
import { StakingConfigService, Web3ConfigService } from '@/config';
1111
import { type ExchangeClient } from '@/modules/exchange';
1212
import { ExchangeClientFactory } from '@/modules/exchange/exchange-client.factory';
13-
import {
14-
ExchangeApiKeyNotFoundError,
15-
ExchangeApiKeysService,
16-
} from '@/modules/exchange-api-keys';
13+
import { ExchangeApiKeysService } from '@/modules/exchange-api-keys';
1714
import { UserEntity, UserNotFoundError, UserRepository } from '@/modules/user';
1815
import { WalletWithProvider, Web3Service } from '@/modules/web3';
1916
import { mockWeb3ConfigService } from '@/modules/web3/fixtures';
@@ -72,12 +69,12 @@ describe('StakingService', () => {
7269

7370
describe('getExchangeStakedBalance', () => {
7471
const userId = faker.number.int();
75-
it('throws ExchangeApiKeyNotFoundError when user has no exchange keys', async () => {
72+
it('returns 0 when user has no exchange keys', async () => {
7673
mockExchangeApiKeysService.retrieve.mockResolvedValueOnce(null);
7774

7875
await expect(
7976
stakingService.getExchangeStakedBalance(userId),
80-
).rejects.toBeInstanceOf(ExchangeApiKeyNotFoundError);
77+
).resolves.toBe(0);
8178
});
8279

8380
it('returns balance fetched from exchange client', async () => {

packages/apps/reputation-oracle/server/src/modules/staking/staking.service.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import { SupportedExchange } from '@/common/constants';
66
import { StakingConfigService, Web3ConfigService } from '@/config';
77
import logger from '@/logger';
88
import { ExchangeClientFactory } from '@/modules/exchange/exchange-client.factory';
9-
import {
10-
ExchangeApiKeyNotFoundError,
11-
ExchangeApiKeysService,
12-
} from '@/modules/exchange-api-keys';
9+
import { ExchangeApiKeysService } from '@/modules/exchange-api-keys';
1310
import { UserNotFoundError, UserRepository } from '@/modules/user';
1411
import { Web3Service } from '@/modules/web3';
1512
import { formatStake } from '@/utils/stake';
@@ -34,7 +31,7 @@ export class StakingService {
3431
async getExchangeStakedBalance(userId: number): Promise<number> {
3532
const apiKeys = await this.exchangeApiKeysService.retrieve(userId);
3633
if (!apiKeys) {
37-
throw new ExchangeApiKeyNotFoundError(userId);
34+
return 0;
3835
}
3936

4037
const client = await this.exchangeClientFactory.create(

0 commit comments

Comments
 (0)