logoalt Hacker News

arghwhattoday at 8:20 AM3 repliesview on HN

Interceptors are just wrappers in disguise.

    const myfetch = async (req, options) => {
        let options = options || {};
        options.headers = options.headers || {};
        options.headers['Authorization'] = token;
    
        let res = await fetch(new Request(req, options));
        if (res.status == 401) {
            // do your thing
            throw new Error("oh no");
        }
        return res;
    }
Convenience is a thing, but it doesn't require a massive library.

Replies

nailertoday at 9:15 AM

That fetch requires so many users to rewrite the same code - that was already handled well by every existing node HTTP client- says something about the standards process.

show 1 reply
pixel_poppingtoday at 9:07 AM

but it does for massive DDoS :p