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

What does this? #14

Open
br14n-sol opened this issue Dec 8, 2021 · 3 comments
Open

What does this? #14

br14n-sol opened this issue Dec 8, 2021 · 3 comments

Comments

@br14n-sol
Copy link
Contributor

const { data } = await axios('https://blockchain.info/q/addressbalance/' + address + '?confirmations=3');
if (data.includes('error')) { // this
   return -1;
}

I understand that axios with the status 404 directly throws an error, so the check does not work, right?

@roberthgnz
Copy link
Contributor

Works, because the data return this...

{
  "error": "not-found-or-invalid-arg",
  "message": "Item not found or argument invalid"
}

@br14n-sol
Copy link
Contributor Author

Works, because the data return this...

{
  "error": "not-found-or-invalid-arg",
  "message": "Item not found or argument invalid"
}

I think you misunderstood what I meant 😅

In axios, when a call returns a 404 status code, it directly throws an error stopping the application completely, for example, the following code:

const not_exist = await walletfy.getBalance('btc', 'not_exist')
console.log(not_exist)

would throw the following in the console:

(node:10200) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
    at createError (~\Walletfy\node_modules\axios\lib\core\createError.js:16:15)
    at settle (~\Walletfy\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (~\Walletfy\node_modules\axios\lib\adapters\http.js:293:11)
    at IncomingMessage.emit (events.js:387:35)
    at endReadableNT (internal/streams/readable.js:1317:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:10200) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catchate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:10200) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This type of errors should be handled internally in the library and return something more descriptive to the user.


I did something for it in the sumcoin implementation, following what was mentioned in Pull request #4

const not_exist = await walletfy.getBalance('sum', 'not_exist')
console.log(not_exist)

returns the following in the console:

-1

@roberthgnz
Copy link
Contributor

Works, because the data return this...

{
  "error": "not-found-or-invalid-arg",
  "message": "Item not found or argument invalid"
}

I think you misunderstood what I meant 😅

In axios, when a call returns a 404 status code, it directly throws an error stopping the application completely, for example, the following code:

const not_exist = await walletfy.getBalance('btc', 'not_exist')
console.log(not_exist)

would throw the following in the console:

(node:10200) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
    at createError (~\Walletfy\node_modules\axios\lib\core\createError.js:16:15)
    at settle (~\Walletfy\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (~\Walletfy\node_modules\axios\lib\adapters\http.js:293:11)
    at IncomingMessage.emit (events.js:387:35)
    at endReadableNT (internal/streams/readable.js:1317:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:10200) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catchate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:10200) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This type of errors should be handled internally in the library and return something more descriptive to the user.

I did something for it in the sumcoin implementation, following what was mentioned in Pull request #4

const not_exist = await walletfy.getBalance('sum', 'not_exist')
console.log(not_exist)

returns the following in the console:

-1

Right, I saw the same error when you put an address that does not exist, the ideal is to do as you have mentioned catch the error

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

2 participants