Hello,
I've got this error when i want to use superagent to send an API request :
superagent: Enable experimental feature http2
(node:20298) ExperimentalWarning: The http2 module is an experimental API.
(node:20298) UnhandledPromiseRejectionWarning: Error: Unauthorized
at Request.callback (/home/admin/www/imf-nodeapps/node_modules/superagent/lib/node/index.js:783:15)
at IncomingMessage.parser (/home/admin/www/imf-nodeapps/node_modules/superagent/lib/node/index.js:1015:18)
at emitNone (events.js:106:13)
at Stream.emit (events.js:208:7)
at Unzip.unzip.on (/home/admin/www/imf-nodeapps/node_modules/superagent/lib/node/unzip.js:55:12)
at emitNone (events.js:111:20)
at Unzip.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:20298) 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: 1)
(node:20298) [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
do you have any ideas what i have to do?
thanks
Did you intentionally enable HTTP2? Does it work over HTTP1?
no, i'm installing it without using any http services. i just want to use
it to request to an API l.
just npm install superagent, then use superagent.post() without anything
else. and its happen
On Wed, Oct 31, 2018, 20:05 Kornel <[email protected] wrote:
Did you intentionally enable HTTP2? Does it work over HTTP1?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/visionmedia/superagent/issues/1430#issuecomment-434678982,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AItZe7FNr416Ebk92qigDSa8-F9ckvYvks5uqaAogaJpZM4YDVkk
.
OK, I've checked the code:
Ignore the HTTP2 line. It's always printed on Node 10 and later. It's not an error, and it doesn't mean anything.
The error is about lack of .catch() in your code.
Your problem is only later "UnhandledPromiseRejectionWarning: Error: Unauthorized". That means you have made HTTP request to a server, but the server returned status 403, and you've ignored that error by not having .catch() in your code.
Every time you use .then(), you must also catch Promise errors (i.e. have .catch() somewhere later, or 2-argument version of .then(), or use async/await syntax instead of then()).
When you launch node, add --trace-warnings, e.g.
node --trace-warnings index.js
and it will show you where you must add .catch() calls.
i see, it all good when i add .catch()
thank you so much, i've learned something new again today :)
but when i add --trace-warnings, it said something like this :
(node:1348) ExperimentalWarning: The http2 module is an experimental API.
at process.emitWarning (internal/process/warning.js:133:13)
at http2.js:3:9
at NativeModule.compile (bootstrap_node.js:597:7)
at Function.NativeModule.require (bootstrap_node.js:542:18)
at Function.Module._load (module.js:484:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
can i just ignore that?
Yes, you can ignore everything that mentions http2.
ok, im all good now.
thanks! :)
Any chance we could get the message disabled (at least on node 10)?
It's disabled on master
Most helpful comment
OK, I've checked the code:
Ignore the HTTP2 line. It's always printed on Node 10 and later. It's not an error, and it doesn't mean anything.
The error is about lack of
.catch()in your code.Your problem is only later "UnhandledPromiseRejectionWarning: Error: Unauthorized". That means you have made HTTP request to a server, but the server returned status 403, and you've ignored that error by not having
.catch()in your code.Every time you use
.then(), you must also catchPromiseerrors (i.e. have.catch()somewhere later, or 2-argument version of.then(), or useasync/awaitsyntax instead ofthen()).When you launch node, add
--trace-warnings, e.g.and it will show you where you must add
.catch()calls.