Local server did not return a valid JSON response: undefined


#1

Hi everyone,

I get the following error message:

Local server did not return a valid JSON response: undefined

It seems to appear if my GET-request needs around 7s to respond. In the console log right after this error message comes the correct response. But then it’s already to late and the google assistant shows an error.

  1. Request gets send
  2. error in console
  3. Response received
  4. Jovo Response send to google assistant

Do you know where I could catch this error and react to it? Or maybe extend some timeout? Right now it seems to be a matter of seconds. With 4s response time it works.

I use axios for my requests. But this error never reaches the catch block of the axios-request.

thanks!


#2

Axios requests run asynchronously; they return a Promise, and if you want to use the result you have to wait for that promise to complete. Yes, that means all the code above the wait has to be in routines declared as async, since otherwise you can’t wait.

(I had to work through that in my New Sounds On Demand skill, though it’s probably too complicated and JS-naive to be a good example.)

WARNING: Most folks don’t realize this, but HTTP requires that GETs be idempotent. The protocol reserves the right for applications to issue the GET more than once and have that be safe. If you intend your request to have side effects, you probably want POST instead. (I found this one the hard way, some years ago.)


#3

Hi @keshlam

thanks for your help. I already have from front to back the async await keywords. But I sure check them again.

Oh ok, I didn’t know that. That could be a reason for this behaviour. But then, shouldn’t my catch-error block get the “undefined” response from the first GET request? Only the second one with the real response reaches my code in the then-block.
I just don’t really understand from where the console-output “undefined” comes. I would expect that it should call my catch or at least then block.

Right now we optimized the backend calculations and now we are always < 4s and that works. But it still bothers me.