2
votes

I was developing a few Office Outlook Web Add-ins and in none of them could I receive an response error message. Independently of the error that API returns I receive the following data object in fail function:

readyState: 0
responseText: ""
status: 0
statusText: "error"
withCredentials: true

Moreover in the Visual Studio or Browser JavaScript Console console I get:

Origin https://localhost:44347 not found in Access-Control-Allow-Origin header.

XMLHttpRequest: Network Error 0x80700013, Could not complete the operation due to error 80700013.

I would like to point out that CORS is enabled on the server, and I got this error independently from the action taken. It is the same when I give wrong parameter or make a typo in url. I would also like to point out that API is OK, and such a thing does not happen when I request using JS in the browser (out of Office) or applications. I get a normal error messages from the server then.

In the example above the test is from localhost, but exactly the same situation is when hosted on remote web server.

What is wired about this is that I normally get success replies (with code and message).

What I would like to achieve is to get an error response as the server returns them. It is really hard to notify user what may be wrong with his request without this info.

[Edit] For example, when I do the following request in a Outlook Add-in and I set the fake token I receive the mentioned error (or rather no error):

$.ajax({
    type: 'GET',
    url: API_URL + "/api/rooms/",
    beforeSend: function (xhr) {
        $.ajaxSettings.beforeSend(xhr);
        xhr.setRequestHeader("Authorization", "Bearer " + token);
    },
    contentType: "application/json",
});

However, when I do the save request using Advanced REST Client I got 403:

"description": "You do not have permission to perform this action.",
"message": "",
"code": "permission-denied",
"status": "fail"

It happens in all Outlook version for me.

1
No one has any idea about that? - Niko
How are you getting/setting the Auth token for making the REST call? Could you also share a snippet of code that reproduces this issue on OutlookAddIn but not in a browser like you mention? Also, what Outlook client(Outlook WebApp, Outlook Desktop , etc.) are you trying to target? - Outlook Add-ins Team - MSFT
MSFT, please see the edit. - Niko
Hi, why are you setting a fake token in your scenario? And where are you setting it at? I am sorry I do not see this part in the code snippet you have shared. - Outlook Add-ins Team - MSFT
I set the fake token to generate the error. I could also set the fake endpoint or set the wrong parameter - it does not matter. The error is always the same. (in the example the security token should be where token var is) Am I the only one that experience this? - Niko

1 Answers

0
votes

The issue is that the office add-in is sending a request to your web application over HTTP and the web project that gets created (I'm assuming you're using the Office add-in templates from visual studio) is by default configured for SSL, i.e an HTTPS connection. Whilst this is recommended for production apps, for debugging purposes you can simply click on your web project, then in visual studio click view on the Menu Bar - > then select the properties window -> then set SSL enabled to false. (see attached Image)

https://i.stack.imgur.com/Lvybn.png

Hope this helps!