tomas / needle

Nimble, streamable HTTP client for Node.js. With proxy, iconv, cookie, deflate & multipart support.

Home Page:https://www.npmjs.com/package/needle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some errors can't be caught

adityapatadia opened this issue · comments

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.

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

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

commented

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);
});