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
282 stars 73 forks source link

Access raw response #184

Open anujkumar-df opened 7 years ago

anujkumar-df commented 7 years ago

Hi Gautam,

Is there any way to access raw response sent by exchange ?

gautamsi commented 7 years ago

You can modify servicerequestbase.ts to create a hook there. Or better create a callback in ewsservicexmlreader.ts where the xml is transformed.

anujkumar-df commented 7 years ago

If you can give some pseudo code, that would be great. I mean where you put callback, etc.

gautamsi commented 7 years ago

if you are not in hurry, I can add this as feature request.

anujkumar-df commented 7 years ago

Well tbh, I have a deadline to meet :), so if you can provide me a pseudo code, it would be great and I can perhaps create a PR in lets say few days.

gautamsi commented 7 years ago

take a look at XHRDefaults.ts files. you can add a static/instance field registering callbbacks like this

class XHRDefaults{
static EWSCallBacks:Fucntion[] = [];
//------ other code
// - -- in function XHR: before line ---- resolve(setupXhrResponse(xhrResponse));
if(XHRDefaults.EWSCallBacks && EWSCallBacks.length >0){
  //other validations
  XHRDefaults.EWSCallBacks.foreach(cb=>{
       cb(xhrResponse.response)
  });
}
}

register callback when you import ews - before creating any instance of service.

var ews = require("ews-javascript-api");
ews.XHRDefaults.EWSCallBacks.push(function(raw){console.log(raw)});

does this help?

that would still be non optimal solution, EWS has some mechanism of writing tracing adapters which you can track in #80

gautamsi commented 7 years ago

when you use instance field, you have to get the XHRApi property from ExchangeService instance.

var ews = require("ews-javascript-api")
var svc = new ews.ExchangeService(params);
svc.XHRApi.EWSCallBacks.push(fucntion_Call);