Office-js addin with webapi. Failed to fetch

RaoulRSV 31 Reputation points
2021-08-27T10:23:13.647+00:00

Windows 10 20H2, VS 2019 Community

Application contains one office-js addin (typescript) + one Webapi core (c#) in a container, both components communicating with a fetch function thanks to cors.
It works properly on my local computer.
I published both components on azure, the webapi component being derived as a container instance. I checked that the correct azure addin address was entered in the webapi startup module.

Now, each individual component works properly (proof with messages from the addin and with postman for the webapi) but fetch function raises errors (message = "failed to fetch").

Could someone tell me what I did miss ?

Thanks in advance.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,404 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
942 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,408 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,731 Reputation points
    2021-09-01T20:46:20.707+00:00

    a fetch error only happens from a network or CORS error. you don't show the fetch code, so the error could be from after the fetch. for example:

    fetch('http://example.com/movies.json')
      .then(response => response.json())
      .then(data => console.log(data));
    

    will throw an error if the response is not json (say a 500 error returning html). try:

    fetch('http://example.com/movies.json')
      .then(response => {
           if (!response.ok) throw (`invalid response: ${response.status}`); 
           return response.json()
      })
      .then(data => console.log(data));