ews-javascript-api icon indicating copy to clipboard operation
ews-javascript-api copied to clipboard

Issue with @ewsjs/xhr and ews-javascript-api cann't read property of undefined

Open MahmoudShaltoot opened this issue 1 year ago • 2 comments
trafficstars

Hello! I am trying to initialize calender folder object using ews.CalendarFolder.Bind(exch, ews.WellKnownFolderName.Calendar) but I get this error

TypeError: Cannot read properties of undefined (reading 'headers')
    at NtlmProvider.preCall (D:\TDRA\tra-gate-api\node_modules\@ewsjs\xhr\dist\ntlmProvider.js:48:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async XhrApi.xhr (D:\TDRA\tra-gate-api\node_modules\@ewsjs\xhr\dist\xhrApi.js:123:25

Here is the code

      // create instance
      let xhr = new XhrApi({rejectUnauthorized: false})
        .useNtlmAuthentication(credentials.userName, credentials.password);

      ews.ConfigurationApi.ConfigureXHR(xhr);

      var service = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
      service.Credentials = new ews.WebCredentials(credentials.userName, credentials.password);
      service.Url = new ews.Uri(this.app.options['exchangeServiceUrl']);
      service.ImpersonatedUserId = new ews.ImpersonatedUserId(ews.ConnectingIdType.SmtpAddress, email)

      // Initialize the calendar folder object with only the folder ID.
      let calendar = await ews.CalendarFolder.Bind(service, ews.WellKnownFolderName.Calendar);
      ...

This issue occurs with ews.CalendarFolder.Bind(service, ews.WellKnownFolderName.Calendar);

PS: I tried to figure out what is the issue from the package I found that this request returns undefined

link: https://github.com/ewsjs/xhr/blob/a6265b03ba092c3712e27d9d3366bbf7add49ed3/src/ntlmProvider.ts#L54C31-L54C64

image

MahmoudShaltoot avatar Apr 24 '24 10:04 MahmoudShaltoot

can you find out why err.response is undefined or would it be undefined all the time.

gautamsi avatar Apr 25 '24 03:04 gautamsi

Hii @gautamsi, I found that there is a connectivity issue with exchange server, Axios throws an error with a message connect ETIMEDOUT 185.54.18.22:443

AxiosError: connect ETIMEDOUT 185.54.18.22:443 at AxiosError.from (D:\TDRA\tra-gate-api\node_modules\axios\dist\node\axios.cjs:836:14) at ClientRequest.handleRequestError (D:\TDRA\tra-gate-api\node_modules\axios\dist\node\axios.cjs:3086:25) at ClientRequest.emit (node:events:514:28) at TLSSocket.socketErrorListener (node:_http_client:501:9) at TLSSocket.emit (node:events:514:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) at Axios.request (D:\TDRA\tra-gate-api\node_modules\axios\dist\node\axios.cjs:3876:41) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async NtlmProvider.preCall (D:\TDRA\tra-gate-api\node_modules\@ewsjs\xhr\dist\ntlmProvider.js:43:30) at async XhrApi.xhr (D:\TDRA\tra-gate-api\node_modules\@ewsjs\xhr\dist\xhrApi.js:123:25) { port: 443, address: '185.54.18.22', syscall: 'connect', code: 'ETIMEDOUT', errno: -4039, ...

Can we throw an error here?

Thank you for your help.

MahmoudShaltoot avatar Apr 25 '24 07:04 MahmoudShaltoot