Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fetch failing

ANSWERED

I've found a couple of similar posts - it seems the Companion is very picky With the fetch.

 

I have copied an example (Bart), and modified it to my needs. 

 

When I change the URL to non-json resources, the Companion is able to do the fetch, so there is something it can't cope with with my back-end, but I get no information about what actually goes wrong - only "TypeError Failed to fetch"

 

I could be able to actually change the way the back end responds, but I do not know what to change. 

 

The data is downloaded nicely With chrome on the phone, and various browsers on the computer. The response header looks like this in Firefox:

 

Cache-Control: no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Expires: -1
Vary: Accept-Encoding
Server: Kestrel
X-Powered-By: ASP.NET
Set-Cookie: .AspNetCore.Session=C2<*** cut for brewety ***> uit5oAkrcMzx2C%2FC; path=/; samesite=lax; httponly
ARRAffinity=eaaff9648d472c3da0da1bd2c3d7451e441df96704916ba7b506b6150b26cdc7;Path=/;HttpOnly;Domain=<** my service **>.azurewebsites.net
Date: Thu, 25 Jan 2018 21:54:50 GMT

 

The payload looks like this (cut a bit)

[{"displayName":"<one account name>","publicReference":"61914","saldo":1000.200},{"displayName":"<another account name>","publicReference":"30633","saldo":2000.870}]

 

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Thank you for the suggestion.

 

I have now solved the problems, and the app is working.

 

Along my way to fixing this, one of the things I did was to add CORS-support to the back-end.

 

I got another error along my way, which was the one active when I asked the question - and this might be a result of my inexperience with Javascript and fetch(). The problem I used the most time fixing was that a "console.log(<something>)" caused subsequent <obj>.json() to fail with the TypeError.

 

Some tips from a newbie to another...

* read this https://developers.google.com/web/updates/2015/03/introduction-to-fetch

* debug the code locally with developer tools in Chrome https://developers.google.com/web/tools/chrome-devtools/javascript/ - the snippets feature is invaluable.

 

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

Does your back-end specify a "Access-Control-Allow-Origin" header? I don't see it in your response header you provided and sometimes that might be the issue.

Best Answer

Thank you for the suggestion.

 

I have now solved the problems, and the app is working.

 

Along my way to fixing this, one of the things I did was to add CORS-support to the back-end.

 

I got another error along my way, which was the one active when I asked the question - and this might be a result of my inexperience with Javascript and fetch(). The problem I used the most time fixing was that a "console.log(<something>)" caused subsequent <obj>.json() to fail with the TypeError.

 

Some tips from a newbie to another...

* read this https://developers.google.com/web/updates/2015/03/introduction-to-fetch

* debug the code locally with developer tools in Chrome https://developers.google.com/web/tools/chrome-devtools/javascript/ - the snippets feature is invaluable.

 

Best Answer
0 Votes