Skip to content

Commit 3daf54a

Browse files
authored
fix: handle JSON-RPC errors from score-api (#899)
1 parent 73a6e41 commit 3daf54a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ export async function getScores(
238238
body: JSON.stringify({ params })
239239
});
240240
const obj = await res.json();
241+
242+
if (obj.error) {
243+
return Promise.reject(obj.error);
244+
}
245+
241246
return options.returnValue === 'all'
242247
? obj.result
243248
: obj.result[options.returnValue || 'scores'];

test/e2e/utils/getScores.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test, expect, describe } from 'vitest';
2+
import { getScores } from '../../../src/utils';
3+
4+
describe('test getScores', () => {
5+
test('getScores should returns a promise rejection on error from score-api', async () => {
6+
expect.assertions(1);
7+
await expect(
8+
getScores('test.eth', [], '1', ['0x0'])
9+
).to.rejects.toHaveProperty('code');
10+
});
11+
});

0 commit comments

Comments
 (0)