8000 added informative error when account is not found by rozum-dev · Pull Request #532 · near/near-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

added informative error when account is not found #532

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const qs = require('querystring');
const chalk = require('chalk'); // colorize output
const open = require('open'); // open URL in default browser
const { KeyPair, utils, transactions } = require('near-api-js');

const connect = require('./utils/connect');
const verify = require('./utils/verify-account');
const capture = require('./utils/capture-login-success');
Expand Down
31 changes: 30 additions & 1 deletion utils/inspect-response.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
const explorer = require('./explorer');

const config = require('../get-config')();
const chalk = require('chalk'); // colorize output
const util = require('util');


const checkExistAccount = (error, options) => {
if(!String(error).includes('does not exist while viewing')) return false;

console.log(chalk`\n{bold.red Account {bold.white ${options.accountId}} is not found in {bold.white ${config.helperAccount}} network.\n}`);

const re = new RegExp('[^.]*$', 'gi');
const suffix = String(options.accountId).match(re)[0];

switch(suffix) {
case 'near':
console.log(chalk`{bold.white Use export NEAR_ENV=mainnet to use MainNet accounts. \n}`);
break;
case 'testnet':
console.log(chalk`{bold.white Use export NEAR_ENV=testnet to use TestNet accounts. \n}`);
break;
case 'betanet':
console.log(chalk`{bold.white Use export NEAR_ENV=betanet to use BetaNet accounts. \n}`);
break;
}

return true;
};

const prettyPrintResponse = (response, options) => {
if (options.verbose) {
console.log(formatResponse(response));
Expand All @@ -13,6 +39,9 @@ const prettyPrintResponse = (response, options) => {
};

const prettyPrintError = (error, options) => {
const isCheckExistAccountError = checkExistAccount(error, options);
if(isCheckExistAccountError) return;

console.log('An error occured');
console.log(formatResponse(error));
const txnId = getTxnIdFromError(error);
Expand Down
0