When calling await fetch

We have updated our wrangler’s to version 3 and are getting strange errors when called an external api (Contentstack), the wrangler code can be seen in the below image. We try the call three times with a timestamp param before giving up and sometimes that works. The thing is we’ve never been able to get the API to fail testing it locally and so are wondering if there is something we should be doing differently in the wrangler when fetching data?

The log when we get these errors can also be seen below, as you can see we seem to be getting an empty string response from the fetch call to the API.

Any ideas on troubleshooting this?


Given “Could not parse” message that is logged, and the fact that is in a try...catch, resp is not valid JSON. As this is logged, and there is nothing showing, I might suggest resp === null.

If you curl the url that is logged from such an event, do you get a non-null response?

Thanks for the response. Yep, not using curl but hitting it in Postman gives us the expected response, and sometimes the second or third call in the worker works successfully. For example that log shown worked on the second call, same API. There are also multiple successful responses on the first call to the API. I’m hoping to have a way to figure out if the issue is in the worker code or at the API’s end.

I would lean towards the API.

Does it happen when there is a number of calls in quick succession?
Or does it normally happen after a period of inactivity?
Perhaps log is response status code as well. If not a 2xx that could provide more information.

Hmm, yeah good plan, will do that and try to get more info, thanks

Looks like the broken calls are returning 400 status code, I’ll pick it up with the API provider. Thanks for the input, was going in circles.

1 Like

@samaritanau did you resolve this? Because I feel I have a very similar issue with CF Pages (see here Await fetch() is no longer working properly for Remix loader on CF pages) and I’m very confident that my external resource is OK.

Don’t cross post please @ransom especially is this is likely completely unrelated to your issue. Continue the discussion on the thread you created

@ransom No resolution yet, working with API provider to hopefully find out if the failing calls are making it to their end or if something is going on at the wrangler end. Will update this ticket once a resolution is found.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.