javascriptnode.jsaxioscoverity

Setting axios timeout value has no effect


we have set the timeout in the code like

    axios.defaults.timeout === 3000;
......
 try {
        const aData = await axios.get(Url, {
            headers: {
                'Authorization': authToken.authHeaderValue,
            },
            httpAgent: new https.Agent({
                keepAlive: true
            }),
        });
....

However in the static code analysis(polaris synopsis) test it shows as

Discarding the result of operator "===" in "axios.defaults.timeout === 3000". What was this code intended to accomplish?

Is this setting or assignment of the variable discarded?


Solution

  • The === operator in Javascript is a boolean test, not an assignment. The line of code:

    axios.defaults.timeout === 3000;
    

    has no effect. Presumably, it was intended to set timeout, for example:

    axios.defaults.timeout = 3000;
    

    The erroneous syntax in question, using ===, evidently (from a comment) comes from a medium.com article (blog) by Ekebor Kelechi, Axios.defaults.timeout. That article obviously has a mistake, intending to use =, as === by itself never has an effect in Javascript.