Fetch Error
See original GitHub issueI am unable to figure out what is causing this error. It seems to happen if I have more than one or two page calls:
Unhandled error { FetchError: invalid json response body at https://en.wikipedia.org/w/api.php?format=json&action=query&redirects=&prop=coordinates&titles=Lone%20Peak%20High%20School&origin=* reason: Unexpected token < in JSON at position 0
> at /Users/swirig/www/roam-platform/node_modules/node-fetch/lib/index.js:272:32
> at process._tickCallback (internal/process/next_tick.js:68:7)
> message:
> 'invalid json response body at https://en.wikipedia.org/w/api.php?format=json&action=query&redirects=&prop=coordinates&titles=Lone%20Peak%20High%20School&origin=* reason: Unexpected token < in JSON at position 0',
> type: 'invalid-json' }
Here is my function:
const getWikiContent = functions.https.onCall(async(data, context) => {
const wikPage = await wiki().page('Eiffel Tower');
const results = await Promise.all([
wikPage.mainImage(),
wikPage.content(),
wikPage.summary(),
wikPage.coordinates()
]);
...
Is this a bug? Am I handling the promises wrong? Is there an issue with running more than one request in a row like this? I have tried multiple variations of the above. If I comment out coordinates it will error with the mainImage call… It seems to work sometimes with only two calls, but I can’t seem to figure out what is causing the issue in the first place. Thanks in advance for your help.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Using the Fetch API - MDN Web Docs
A fetch() promise will reject with a TypeError when a network error is encountered or CORS is misconfigured on the server-side, ...
Read more >Fetch: reject promise and catch the error if status is not OK?
Fetch promises only reject with a TypeError when a network error occurs. Since 4xx and 5xx responses aren't network errors, there's nothing ...
Read more >Implement error handling when using the Fetch API - web.dev
When the Fetch API throws errors #. This example uses a try / catch block statement to catch any errors thrown within the...
Read more >Handling Failed HTTP Responses With fetch() - TJ VanToll
Per MDN, the fetch() API only rejects a promise when a “network error is encountered, although this usually means permissions issues or ...
Read more >Fetch - Error Handling for Failed HTTP Responses and ...
The fetch() function will automatically throw an error for network errors but not for HTTP errors such as 4xx or 5xx responses.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you hack up the original code you’ll see that this is the message returned from Wikipedia:
To fix it, you’ll have to follow their User-Agent policy. The way to implement this in code is to replace the call to
wiki()
with:Perhaps the library should find 429 errors and return a useful response?
Also, an easier way to supply user-agent would be appreciated.
Yes, see #143.