Skip to content

Commit

Permalink
feat: 馃幐 Make unsupported versions an warning instead of error
Browse files Browse the repository at this point in the history
  • Loading branch information
polymath-eric committed Mar 3, 2022
1 parent 7586851 commit e6da7bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/Polymesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,16 @@ export class Polymesh {
} = params;
let context: Context;

await assertExpectedChainVersion(nodeUrl);
await assertExpectedChainVersion(nodeUrl).catch(error => {
if (
error instanceof PolymeshError &&
error.message.includes('Unsupported Polymesh version')
) {
console.warn(error.message);
} else {
throw error;
}
});

try {
const { types, rpc } = schema;
Expand Down
33 changes: 23 additions & 10 deletions src/__tests__/Polymesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,38 @@ describe('Polymesh Class', () => {
});
});

test('should throw an error if the Polymesh version does not satisfy the supported version range', async () => {
test('should warn if the Polymesh version does not satisfy the supported version range', async () => {
const error = new PolymeshError({
code: ErrorCode.FatalError,
message: 'Unsupported Polymesh version. Please upgrade the SDK',
data: { supportedVersionRange: SUPPORTED_VERSION_RANGE },
});
versionStub.rejects(error);
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {
// no-op
});

let err;
try {
await Polymesh.connect({
await expect(
Polymesh.connect({
nodeUrl: 'wss://some.url',
});
} catch (e) {
err = e;
}
})
).resolves.not.toThrow();
expect(warn).toBeCalled();
warn.mockRestore();
});

expect(err.message).toBe('Unsupported Polymesh version. Please upgrade the SDK');
expect(err.data.supportedVersionRange).toBe(SUPPORTED_VERSION_RANGE);
test('should throw an error if the Polymesh version check could not connect to the node', async () => {
const error = new PolymeshError({
code: ErrorCode.FatalError,
message: 'Unable to connect',
});
versionStub.rejects(error);

return expect(
Polymesh.connect({
nodeUrl: 'wss://some.url',
})
).rejects.toThrowError(error);
});

test('should throw an error if the middleware credentials are incorrect', async () => {
Expand Down

0 comments on commit e6da7bd

Please sign in to comment.