ews-javascript-api
ews-javascript-api copied to clipboard
Promise is rejected with incomplete error
trafficstars
In some cases promises are rejected with error that has empty message and zero error code. For example, the code below results in such an error. HttpStatusCode is not null. So it's still possible to get some information but it would be better to set message and errorCode as well.
PS This is true only in the case of basic authentication.
/* eslint-disable no-console */
const {
CalendarView, ConfigurationApi, ExchangeService, ExchangeCredentials, Uri, Mailbox, WellKnownFolderName, FolderId
} = require('ews-javascript-api');
ConfigurationApi.SetXHROptions({ rejectUnauthorized: false });
const exch = new ExchangeService(3);
exch.Credentials = new ExchangeCredentials('username', 'password');
exch.Url = new Uri('https://github.com'); // <=== this gives HttpStatusCode = 404
const startDate = new Date();
startDate.setHours(0);
startDate.setMinutes(0);
startDate.setSeconds(0);
startDate.setMilliseconds(0);
const endDate = new Date(startDate);
endDate.setDate(startDate.getDate() + 1);
const cv = new CalendarView(startDate.toISOString(), endDate.toISOString(), 100);
const folder = new FolderId(WellKnownFolderName.Calendar, new Mailbox('[email protected]'));
exch.FindItems(folder, null, null, cv, null, null)
.catch((err) => {
console.log(err);
});
when you are calling a non exchange sever, then it really does not have way to parse it. in this case I see only this in response code, probably because github server sent text/xml code.
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<status type="integer">404</status>
<error>Not Found</error>
</hash>