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

unhandled rejection: cannot read property 'documentElement' #364

Open PhilHannent opened 4 years ago

PhilHannent commented 4 years ago

Randomly I get an error in the library, it is not something I can reproduce because it happens randomly.

app.js: unhandledRejection] Root RejectionTypeError: Cannot read property 'documentElement' of undefined at EwsServiceXmlReader.EwsXmlReader (C:\inetpub\src\js\Core\EwsXmlReader.ts:43:57) at new EwsServiceXmlReader (C:\inetpub\src\js\Core\EwsServiceXmlReader.ts:18:9) at FindItemRequest.ServiceRequestBase.ProcessWebException (C:\inetpub\src\js\Core\Requests\ServiceRequestBase.ts:315:30) at C:\inetpub\src\js\Core\Requests\SimpleServiceRequestBase.ts:71:55 at tryCatcher (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\promise.js:547:31) at Promise._settlePromise (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\promise.js:604:18) at Promise._settlePromise0 (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\promise.js:649:10) at Promise._settlePromises (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\promise.js:725:18) at _drainQueueStep (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\async.js:93:12) at _drainQueue (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\async.js:86:9) at Async._drainQueues (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\async.js:102:5) at Immediate.Async.drainQueues [as _onImmediate] (C:\inetpub\room-booking-api-prod\node_modules\bluebird\js\release\async.js:15:14) at processImmediate (internal/timers.js:456:21)

PhilHannent commented 4 years ago

We're running v0.10.2

gautamsi commented 4 years ago

are you running behind a proxy or anything, seems like randomly the response is not of type xml.

PhilHannent commented 4 years ago

It is not behind a proxy, we connect to a range of customers EWS servers and O365.

gautamsi commented 4 years ago

this is definitely some kid of situation where there is some invalid xml coming up. do you know which function it may be breaking or is this random?

PhilHannent commented 4 years ago

I don't have enough information available to me.

I know that we use a lot of FindAppointments() but that we also call Update() on an Appointment. I'd be willing to be 99% it is either of those.

ghost commented 3 years ago

I was wondering if any solution on this issue

gautamsi commented 3 years ago

@JojiePalahang let me know if you have any details on this.

any other information if you feel required for troubleshooting.

PhilHannent commented 3 years ago

My workaround for this was to put a try catch in the constructor and an if statement to protect the documentElement. Office 365 have reverse proxies which occasionally (once a week) spit out error HTML, the XML parser fails but there is no check in this constructor for if the document exists:

https://github.com/gautamsi/ews-javascript-api/blob/ef1ff64aa470bd354089bcd5ea2123b87facc5fe/src/js/Core/EwsXmlReader.ts#L39

Sorry, I should have reported back sooner.