Browse Source

Minor api:setUri validation

Leszek Wiesner 4 years ago
parent
commit
2b7041b12f
2 changed files with 9 additions and 1 deletions
  1. 2 1
      cli/src/Api.ts
  2. 7 0
      cli/src/commands/api/setUri.ts

+ 2 - 1
cli/src/Api.ts

@@ -52,7 +52,8 @@ export default class Api {
         if (!results.length || results.length !== queries.length) {
             throw new CLIError('API querying issue', { exit: ExitCodes.ApiError });
         }
-            return results;
+
+        return results;
     }
 
     async getAccountsBalancesInfo(accountAddresses:string[]): Promise<AccountBalances[]> {

+ 7 - 0
cli/src/commands/api/setUri.ts

@@ -1,5 +1,7 @@
 import StateAwareCommandBase from '../../base/StateAwareCommandBase';
 import chalk from 'chalk';
+import { WsProvider } from '@polkadot/api';
+import ExitCodes from '../../ExitCodes';
 
 type ApiSetUriArgs = { uri: string };
 
@@ -15,6 +17,11 @@ export default class ApiSetUri extends StateAwareCommandBase {
 
     async run() {
         const args: ApiSetUriArgs = <ApiSetUriArgs> this.parse(ApiSetUri).args;
+        try {
+            new WsProvider(args.uri);
+        } catch(e) {
+            this.error('The WS provider uri seems to be incorrect', { exit: ExitCodes.InvalidInput });
+        }
         await this.setPreservedState({ apiUri: args.uri });
         this.log(chalk.greenBright('Api uri successfuly changed! New uri: ') + chalk.white(args.uri))
     }