Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandle rpc error #153

Open
michelem09 opened this issue Jan 30, 2024 · 0 comments
Open

Unhandle rpc error #153

michelem09 opened this issue Jan 30, 2024 · 0 comments

Comments

@michelem09
Copy link

michelem09 commented Jan 30, 2024

How do you handle connection error like wrong password?

I have something like this:

const createBitcoinClient = (settings) => {
  try {
    const bitcoinClient = new bitcoin({
      host: process.env.BITCOIN_NODE_HOST || '127.0.0.1',
      port: process.env.BITCOIN_NODE_PORT || 8332,
      username: process.env.BITCOIN_NODE_USER || 'bitcoin',
      password: process.env.BITCOIN_NODE_PASS || 'bitcoin',
      timeout: 30000,
      ssl: false,
    });

    return bitcoinClient;
  } catch (error) {
    throw error;
  }
};

but if the password is wrong it doesn't seem to throw the error instead the app crashes with:

node_modules/bitcoin-core/src/parser.js:57
      throw new RpcError(response.statusCode, response.statusMessage, { body: response.body });

RpcError: Unauthorized
    at Parser.rpc (/Users/michele/Sites/futurebit/apolloapi-v2/node_modules/bitcoin-core/src/parser.js:57:13)
    at Client.command (/Users/michele/Sites/futurebit/apolloapi-v2/node_modules/bitcoin-core/src/index.js:157:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  body: '',
  code: 401
}

Node.js v21.5.0
[nodemon] app crashed - waiting for file changes before starting...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant