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

Redirect on errors

max-degterev opened this issue · comments

commented

Hi, not sure if it's a bug or me not using the library properly.

I have this quick demo: https://runkit.com/suprmax/5fc78c9c251bb3001a7d3555

const needle = require('needle');

const url = 'http://www.mein-contipark.de';
let calls = 0;

needle.head(url, { follow_max: 2 }, (...args) => {
  calls += 1;
  console.log(`Call #${calls}`, args);
});

When follow_max prop is set first request fails and also redirects. There is no way that I can see to detect that redirect occured. Then second request succeeds but in my application I already assume request failed. Is there a way to detect these error-y redirects?