gautamsi / ews-javascript-api

EWS API for TypeScript/JavaScript - ported from OfficeDev/ews-managed-api - node, cordova, meteor, Ionic, Electron, Outlook Add-Ins
MIT License
281 stars 72 forks source link

Cannot read property 'ResponseClass' of undefined #378

Open marcoancona opened 3 years ago

marcoancona commented 3 years ago

Hi @gautamsi, some (but not all) of our users report a crash while synchronizing their Office 365 account. We could not reproduce the issue with out test account, but our logs show the following error:

TypeError: Cannot read property 'ResponseClass' of undefined
    at t.e.LoadFromXmlJsObject (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:1032676)
    at t.ParseResponseXMLJsObject (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:872562)
    at t.ParseResponse (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:873117)
    at t.e.ReadResponseXmlJsObject (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:898658)
    at t.ReadResponsePrivate (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:917307)
    at /opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:916675
    at c (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:111685)
    at R._settlePromiseFromHandler (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:79811)
    at R._settlePromise (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:80611)
    at R._settlePromise0 (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:81310)
    at R._settlePromises (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:82662)
    at c (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:25167)
    at a (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:25106)
    at i._drainQueues (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:26232)
    at drainQueues (/opt/Morgen/resources/app.asar/extensions/mo-ews-sync/dist/background.js:25:25040)

Running in debug mode, it looks like the parsing of an event is interrupted abruptly but I can't see the reason:

... other 75 events correctly parsed before ...
background.js:337 [t]       Loading property :      Subject
background.js:337 Panel Zoom Interview
background.js:337 [t]       Loading property :      Sensitivity
background.js:337 0
background.js:337 [t]       Loading property :      Body
background.js:337 t {Namespace: 2, OnChange: Array(1), bodyType: 1, text: null}
background.js:337 [mo-ews-sync] Exception: The request failed. Cannot read property 'ResponseClass' of undefined

I understand that this is not very complete information but I was wondering if you any idea of where to look in order to debug this.

ews-javascript-api: 0.10.3

gautamsi commented 3 years ago

Is this trying to load event from calendar?

Based on log can you export the item which has issues?

Also I see that it may be minified lib, can you exclude ews lib from being minified and test again?

marcoancona commented 3 years ago

We investigated further. It turns out that one event has an invalid character in the Body field. The Body looks like the following:

<Body BodyType="Text">
Hi all,&#xD;↵&#xD;↵I need one more acceptance. The candidate&#x1B;$B!G&#x1B;(Bs profile opens. 
</Body>

The problem appears to be with the sequence &#x1B;, which makes the parsing fail. For a reproducible example see: https://codesandbox.io/s/quirky-worker-brfng?file=/src/index.js

Note 1): this does not fail on a Node environment. I suspect that DOMParser works differently than xmldom. Note 2): issue reproducible on any browser console: (new DOMParser()).parseFromString("<Body>Test &#x1B;</Body>", "text/xml")

gautamsi commented 3 years ago

which build you are using for browser?

marcoancona commented 3 years ago

We are using ews-javascript-api 0.10.3 (the latest). Or what version are you referring to?

marcoancona commented 3 years ago

Just to clarify: the problem seems really to be caused by invalid XML data coming from the Outlook server. It appears that xmldom is more robust than the native DOMParser of Chromium when parsing invalid XML.

This is what happens in Chrome: image

When we use ews-javascript-api, either xmldom or DOMParser is used to parse the response. Which one is used depends on the environment (https://github.com/gautamsi/ews-javascript-api/blob/378b7c45fd7518312fd22c27d3d254a0dc1876c0/src/js/ExtensionMethods.ts#L499).

We will temporarily patch the library to force it to use xmldom even in the browser, unless you tell us that this is not a good idea.

gautamsi commented 3 years ago

Try patching for xmldom that should work