bcoin-org / bcurl Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
If a request
call in bcurl fails, the error is not properly caught, resulting in UnhandledPromiseRejectionWarning
.
Simple test case:
const {Client} = require('bcurl');
(new Client()).get('/');
Result:
(node:13878) UnhandledPromiseRejectionWarning: Error: Bad response (wrong content-type).
at Client.request (<node_modules>/bcurl/lib/client.js:194:13)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:13878) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:13878) [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.
Couldn't find a simple solution that didn't require a ton of try/catch blocks around every request. Perhaps @chjj has a simpler solution.
This was discovered while using bclient
, which doesn't properly pass request failures back to the original caller. Possible bclient may also need to be updated to properly handle request errors.
These two lines will concatenate this.path
with endpoint
.
Lines:
Line 205 in 1c1ea33
Line 322 in 1c1ea33
By default this.path
is /
and endpoint
should always start with /
(/wallet/...
)
meaning actual request path will be POST //wallet/...
I noticed this when I tried to use bclient with Bitcoin Core for RPC calls. Because
bclient
will create POST // HTTP
instead of POST / HTTP
bitcoin core will return 404.
We don't notice issue because bweb
will actually normalize
paths on the backend and correctly assume /
path is request path.
Loosely related to: bcoin-org/brq#4
bcurl breaks in browser version when doing get requests because brq expects a this.body
. Fixed on master of brq but need to publish that and upgrade the dependency.
This issue is similar to bcoin-org/brq#7 in that I'm getting unexpected behavior when using bcurl for APIs besides bcoin.
See here:
https://github.com/bcoin-org/bcurl/blob/master/lib/client.js#L211-L217
This gets broken by Kraken's API, which is already frustrating for a few other reasons, but one of them is this -- the API always returns an error
property in the JSON:
https://api.kraken.com/0/public/Ticker?pair=XBTUSD
-->
{"error":[],"result":{"XXBTZUSD":{"a":["3536.10000","2","2.000"],"b":["3535.30000","1","1.000"],"c":["3531.80000","1.58333841"],"v":["8259.75520827","9590.27330937"],"p":["3510.71489","3507.83774"],"t":[12317,14569],"l":["3433.90000","3433.90000"],"h":["3579.80000","3579.80000"],"o":"3502.00000"}}}
Even though the error array is empty, bcurl
detects that the property is there and throws without returning the rest of the object.
This library is pretty small and could be merged with brq (also small) to reduce overhead and improve maintenance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.