tomas / needle

Nimble, streamable HTTP client for Node.js. With proxy, iconv, cookie, deflate & multipart support.
https://www.npmjs.com/package/needle
MIT License
1.63k stars 236 forks source link

Some errors can't be caught #347

Open adityapatadia opened 3 years ago

adityapatadia commented 3 years ago

Please see below code. Error produced by it is not possible to catch and it crashes node.

const http = require("http"),
  https = require("https"),
  url = require("url"),
  needle = require("needle");

const agent = {
  http: new http.Agent({ keepAlive: true }),
  https: new https.Agent({ keepAlive: true })
};

let parsedUrl = url.parse('http://img.tesco.com/Groceries/pi/722/5053990138722/IDShot_540x540.jpg');

let origin_resp = needle('get','http://img.tesco.com/Groceries/pi/722/5053990138722/IDShot_540x540.jpg',{ follow_max: 5, agent: (parsedUrl.protocol == "http:") ? agent.http : agent.https}).then(resp=>{console.log(resp)}).catch(err=>{console.error(err)});

There should be some way to catch such protocol related errors as they can be huge issue if not caught in production.

tomas commented 3 years ago

Thanks for reporting. Will take a look at this next week.

adityapatadia commented 3 years ago

It would be helpful if this is resolved. We are seeing crashes in production env.

max-degterev commented 3 years ago

Let me add something I caught in production as well:

https://runkit.com/601c1f2160893700138f0ad4/601c1f3904c5df001a492012

const needle = require('needle');

const url = 'https://www.elwis.de/DE/dynamisch/gewaesserkunde/wasserstaende/wasserstaendeUebersichtGrafik.html.php?gw=RHEIN';

needle.head(url, (error) => {
  console.log('This just crashed with no error', error);
});