Skip to content

Commit

Permalink
fix: handle JSON-RPC errors from score-api (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored Sep 19, 2023
1 parent 73a6e41 commit 3daf54a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ export async function getScores(
body: JSON.stringify({ params })
});
const obj = await res.json();

if (obj.error) {
return Promise.reject(obj.error);
}

return options.returnValue === 'all'
? obj.result
: obj.result[options.returnValue || 'scores'];
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/utils/getScores.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test, expect, describe } from 'vitest';
import { getScores } from '../../../src/utils';

describe('test getScores', () => {
test('getScores should returns a promise rejection on error from score-api', async () => {
expect.assertions(1);
await expect(
getScores('test.eth', [], '1', ['0x0'])
).to.rejects.toHaveProperty('code');
});
});

0 comments on commit 3daf54a

Please sign in to comment.