Search code examples
outlookoffice-jsoutlook-addinoffice-addinsoutlook-web-addins

Fetching attachment content using getAttachmentContentAsync() reports exception in owa.Addins.js


I am changing my Outlook Addin to fetch attachment contents using the Mailbox API rather than using MS Graph on my server. I'm pretty sure it worked a couple of weeks ago, but I just attempted to push my changes to production and it seems to be broken now.

The addin checks for the presence of Mailbox API set 1.8 using Office.context.requirements.isSetSupported("Mailbox", "1.8") and only attempts to use the API if the API set is supported.

First we fetch the list of attachments on the selected email by accessing the metadata directly if we are in ReadMode, or using the getAttachmentsAsync() if we are in ComposeMode.

Once the user has filled in the rest of the form we present, we iterate through the list of attachments and use getAttachmentContentAsync() on each attachment to fetch the byte array of the content. Once that request completes we make an API call to our server to upload the attachment contents.

But our callback passed into getAttachmentContentAsync() never gets called. No exceptions are returned to my code.

The console log in the browser reports an exception inside of owa.Addins.js when trying to read the __type attribute of some object.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__type')
    at i (owa.Addins.js:2:118601)
    at owa.Addins.js:2:340142
    at Lt (owa.Addins.js:2:353455)
    at owa.Addins.js:2:375939
    at t.invoke (owa.Addins.js:2:880266)
    at h (owa.Addins.js:2:863745)
    at T (owa.Addins.js:2:867431)

I'm at a loss for what to try next. I have verified in the debugger and through log statements that the arguments I pass to the method are defined at the time of calling.

Looking for a clue.

During the testing party on 5 Dec, it was determined that the issue was cross platform and both desktop and web. This morning, 6 Dec, I checked on MacOS Desktop Outlook with the feature flipper set to ON, and the UI code was able to fetch the attachment contents without error. It still fails on Web however.

Reproducing the issue is anything but dramatic, but I uploaded a quick video to YouTube showing the issue. YouTube Link


Solution

  • This is the exception you get when you pass a bad ID into the getAttachmentContentAsync() method.

    In creating the simplest example to reproduce the problem I found that my simple example actually worked. Looking through the existing code I found the problem was a block of code that converted the attachment.id field to the REST safe value, which of corse made the ID unusable. My assumption is that the Mailbox code was getting undefined when looking up the attachment by Id and didn't notice it until it tried to check what type of attachment it was.

    Thanks for the quick attention. Sorry for the noise. But at least now I know that this is the sort of error we get when a bad ID is passed to the getAttachmentContentAsync() method.