brianleroux / tiny-json-http

:anchor: Minimalist HTTP client for JSON payloads.
172 stars 18 forks source link

[Bug] Timeout fault #36

Open b5414 opened 2 years ago

b5414 commented 2 years ago

Hi, there is a simple example with the latest version of the tiny package

try{
    const data = {test: true};

    await tiny.post({
        url: 'some url for post tests',
        data,
        timeout: 15000,
        headers: {Authorization: 'Bearer ' + token},
    }).then(({body})=>({ok: true, data: body})).catch((e)=>({ok: false, err: e.message + 'this not working'}));
}catch(err){
    console.log('this working', err);
}

Unfortunately it returns err: 'timeout is not defined'

and only the external trycatch works, instead of the promised one

Loksly commented 2 weeks ago

tiny-json-http/dist.js:912:24

if (options.timeout) {
        opts.timeout = timeout; /// this is the bug. This should be options.timeout
      }

src code

https://github.com/brianleroux/tiny-json-http/blob/main/_write.js#L44