Skip to content

Commit 993bf0c

Browse files
authored
Reduce Accepted Error codes from MirrorNodeClient.ts (#1746)
* removing anything that is not 404, only 404 should default to null instead of the actual error Signed-off-by: Alfredo Gutierrez <[email protected]> * fixed broken unit tests Signed-off-by: Alfredo Gutierrez <[email protected]> --------- Signed-off-by: Alfredo Gutierrez <[email protected]>
1 parent 4c8d39d commit 993bf0c

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

packages/relay/src/lib/clients/mirrorNodeClient.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,23 @@ export class MirrorNodeClient {
9090

9191
static acceptedErrorStatusesResponsePerRequestPathMap: Map<string, Array<number>> = new Map([
9292
[MirrorNodeClient.GET_ACCOUNTS_BY_ID_ENDPOINT, [404]],
93-
[MirrorNodeClient.GET_BALANCE_ENDPOINT, [400, 404]],
94-
[MirrorNodeClient.GET_BLOCK_ENDPOINT, [400, 404]],
95-
[MirrorNodeClient.GET_BLOCKS_ENDPOINT, [400, 404]],
96-
[MirrorNodeClient.GET_CONTRACT_ENDPOINT, [400, 404]],
97-
[MirrorNodeClient.GET_CONTRACT_RESULTS_BY_ADDRESS_ENDPOINT, [206, 400, 404]],
98-
[MirrorNodeClient.GET_CONTRACT_RESULTS_DETAILS_BY_CONTRACT_ID_ENDPOINT, [400, 404]],
99-
[MirrorNodeClient.GET_CONTRACT_RESULTS_DETAILS_BY_ADDRESS_AND_TIMESTAMP_ENDPOINT, [400, 404]],
100-
[MirrorNodeClient.GET_CONTRACT_RESULT_ENDPOINT, [400, 404]],
101-
[MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_ENDPOINT, [400, 404]],
102-
[MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_BY_ADDRESS_ENDPOINT, [400, 404]],
103-
[MirrorNodeClient.GET_CONTRACT_RESULTS_ENDPOINT, [400, 404]],
104-
[MirrorNodeClient.GET_NETWORK_EXCHANGERATE_ENDPOINT, [400, 404]],
105-
[MirrorNodeClient.GET_NETWORK_FEES_ENDPOINT, [400, 404]],
106-
[MirrorNodeClient.GET_TOKENS_ENDPOINT, [400, 404]],
107-
[MirrorNodeClient.GET_TRANSACTIONS_ENDPOINT, [400, 404]],
108-
[MirrorNodeClient.CONTRACT_CALL_ENDPOINT, [404, 415, 500]],
109-
[MirrorNodeClient.CONTRACT_ADDRESS_STATE_ENDPOINT, [400, 404]],
93+
[MirrorNodeClient.GET_BALANCE_ENDPOINT, [404]],
94+
[MirrorNodeClient.GET_BLOCK_ENDPOINT, [404]],
95+
[MirrorNodeClient.GET_BLOCKS_ENDPOINT, [404]],
96+
[MirrorNodeClient.GET_CONTRACT_ENDPOINT, [404]],
97+
[MirrorNodeClient.GET_CONTRACT_RESULTS_BY_ADDRESS_ENDPOINT, [404]],
98+
[MirrorNodeClient.GET_CONTRACT_RESULTS_DETAILS_BY_CONTRACT_ID_ENDPOINT, [404]],
99+
[MirrorNodeClient.GET_CONTRACT_RESULTS_DETAILS_BY_ADDRESS_AND_TIMESTAMP_ENDPOINT, [404]],
100+
[MirrorNodeClient.GET_CONTRACT_RESULT_ENDPOINT, [404]],
101+
[MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_ENDPOINT, [404]],
102+
[MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_BY_ADDRESS_ENDPOINT, [404]],
103+
[MirrorNodeClient.GET_CONTRACT_RESULTS_ENDPOINT, [404]],
104+
[MirrorNodeClient.GET_NETWORK_EXCHANGERATE_ENDPOINT, [404]],
105+
[MirrorNodeClient.GET_NETWORK_FEES_ENDPOINT, [404]],
106+
[MirrorNodeClient.GET_TOKENS_ENDPOINT, [404]],
107+
[MirrorNodeClient.GET_TRANSACTIONS_ENDPOINT, [404]],
108+
[MirrorNodeClient.CONTRACT_CALL_ENDPOINT, [404]],
109+
[MirrorNodeClient.CONTRACT_ADDRESS_STATE_ENDPOINT, [404]],
110110
]);
111111

112112
private static ETHEREUM_TRANSACTION_TYPE = 'ETHEREUMTRANSACTION';

packages/relay/tests/lib/eth.spec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ describe('Eth calls using MirrorNode', async function () {
877877

878878
it('eth_getBlockByNumber with no match', async function () {
879879
cacheService.clear();
880-
restMock.onGet(`blocks/${blockNumber}`).reply(400, {
880+
restMock.onGet(`blocks/${blockNumber}`).reply(404, {
881881
_status: {
882882
messages: [
883883
{
@@ -1207,7 +1207,7 @@ describe('Eth calls using MirrorNode', async function () {
12071207
it('eth_getBlockByHash with no match', async function () {
12081208
cacheService.clear();
12091209
// mirror node request mocks
1210-
restMock.onGet(`blocks/${blockHash}`).reply(400, {
1210+
restMock.onGet(`blocks/${blockHash}`).reply(404, {
12111211
_status: {
12121212
messages: [
12131213
{
@@ -1260,7 +1260,7 @@ describe('Eth calls using MirrorNode', async function () {
12601260

12611261
it('eth_getBlockTransactionCountByNumber with no match', async function () {
12621262
cacheService.clear();
1263-
restMock.onGet(`blocks/${blockNumber}`).reply(400, {
1263+
restMock.onGet(`blocks/${blockNumber}`).reply(404, {
12641264
_status: {
12651265
messages: [
12661266
{
@@ -1328,7 +1328,7 @@ describe('Eth calls using MirrorNode', async function () {
13281328
it('eth_getBlockTransactionCountByHash with no match', async function () {
13291329
cacheService.clear();
13301330
// mirror node request mocks
1331-
restMock.onGet(`blocks/${blockHash}`).reply(400, {
1331+
restMock.onGet(`blocks/${blockHash}`).reply(404, {
13321332
_status: {
13331333
messages: [
13341334
{
@@ -1397,7 +1397,7 @@ describe('Eth calls using MirrorNode', async function () {
13971397
.onGet(
13981398
`contracts/results?block.number=${defaultBlock.number}&transaction.index=${defaultBlock.count}&limit=100&order=asc`,
13991399
)
1400-
.reply(400, {
1400+
.reply(404, {
14011401
_status: {
14021402
messages: [
14031403
{
@@ -2681,9 +2681,16 @@ describe('Eth calls using MirrorNode', async function () {
26812681
)
26822682
.reply(400, { _status: { messages: [{ message: 'Mocked error' }] } });
26832683

2684-
const result = await ethImpl.getLogs(null, null, null, null, null);
2685-
expect(result).to.exist;
2686-
expect(result.length).to.eq(0);
2684+
let errorReceived = false;
2685+
try {
2686+
const result = await ethImpl.getLogs(null, null, null, null, null);
2687+
} catch (error) {
2688+
errorReceived = true;
2689+
expect(error.statusCode).to.equal(400);
2690+
expect(error.message).to.eq('Mocked error');
2691+
}
2692+
2693+
expect(errorReceived, 'Error should be thrown').to.be.true;
26872694
});
26882695

26892696
it('no filters', async function () {

packages/relay/tests/lib/mirrorNodeClient.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ describe('MirrorNodeClient', async function () {
6868

6969
describe('handleError', async () => {
7070
const CONTRACT_CALL_ENDPOINT = 'contracts/call';
71-
const nullResponseCodes = [404, 415, 500];
72-
const errorRepsonseCodes = [501, 503, 400, 429];
71+
const nullResponseCodes = [404];
72+
const errorRepsonseCodes = [501, 503, 400, 429, 415, 500];
7373

7474
for (const code of nullResponseCodes) {
7575
it(`returns null when ${code} is returned`, async () => {

0 commit comments

Comments
 (0)