Skip to content

Commit

Permalink
fixup! refactor(cardano-services): lift up error handling - move erro…
Browse files Browse the repository at this point in the history
…r handing into `DbSyncAssetProvider`
  • Loading branch information
Ivaylo Andonov committed Sep 12, 2022
1 parent 61db0fa commit 09b85b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/cardano-services/src/Asset/DbSyncAssetProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ export class DbSyncAssetProvider extends DbSyncProvider implements AssetProvider
} catch (error) {
if (error instanceof ProviderError && error.reason === ProviderFailure.ConnectionFailure) {
assetInfo.tokenMetadata = undefined;
} else {
throw error;
}
throw error;
}
}

Expand Down
17 changes: 17 additions & 0 deletions packages/cardano-services/test/Asset/DbSyncAssetProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-shadow */
import { Asset, Cardano, ProviderError, ProviderFailure } from '@cardano-sdk/core';
import {
CardanoTokenRegistry,
Expand Down Expand Up @@ -82,4 +83,20 @@ describe('DbSyncAssetProvider', () => {
name: 'macaron cake token'
});
});

it('returns undefined asset token metadata if the token registry throws a network error', async () => {
const { tokenMetadataServerUrl, closeMock } = await mockTokenRegistry(() => ({ body: {}, code: 500 }));
const tokenMetadataService = new CardanoTokenRegistry({ logger }, { tokenMetadataServerUrl });

provider = new DbSyncAssetProvider({ db, logger, ntfMetadataService, tokenMetadataService });

const asset = await provider.getAsset({
assetId: validAssetId,
extraData: { tokenMetadata: true }
});

expect(asset.tokenMetadata).toBeUndefined();
tokenMetadataService.shutdown();
await closeMock();
});
});

0 comments on commit 09b85b3

Please sign in to comment.