got: Do not use invalid cache
Describe the bug
- Node.js version: 13.3
- OS & version: MacOS Catalina
Actual behavior
I get GotError: Unexpected token in JSON at position 0 in ...
when I add responseType: "json"
.
But this happens 2 times out of 5 … and If I remove the responseType and log the body, all is good…
PS: right before this error there is this warning every time: (node:34140) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Expected behavior
Should be able to parse JSON, I think got tries to parse before getting full response or something like that
Code to reproduce
const body = await got
.get(link, {
cache,
retry: 4
})
.json();
or
const { body } = await got
.get(link, {
cache,
retry: 4,
responseType: 'json'
});
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19
How can I get more? Isn’t good for you? And I checked: 1/2 times the key is removed in the cache file, so the next time he made the request, it’s working, then error, and he removes, etc…
The first character is the
{
.Here’s the cache:
And I will try to provide you a bigger stacktrace, thanks