dman
dman

Reputation: 11064

Rectangular addResponseInterceptor data object undefined while has it in response object

Using Restangular, the get method/promise resolves but the result handed to .then() is empty...with console.log(data); showing undefined. I checked the network tab in chromium debug and the xhr request is good with 200 success...there is a full json response in the body.

Using addResponseInterceptor, I have found that the data argument is undefined, but the response argument shows the object containing the data property with the payload/body.

So, I am left scratching my head.....why is the data argument undefined while the response object properly contains the json payload/response in the response.data?

I need to resolve this so the result is passed to .then() on resolve.

createNode: function(node) {
      var account = "9936";
      var eventId = "0fd6afd9-4aa0-a5c9-ff0b3e60cdcf";
      Restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
          console.log("````````````````");
          console.log(data);
          console.log(operation);
          console.log(what);
          console.log(url);
          console.log(response);
          console.log(deferred);
          console.log("````````````````");
      });

                                                                        node.js:12
undefined                                                               node.js:13
get                                                                     node.js:14
event                                                                    node.js:15
/1.0/loadbalancers/account/9936/event/0fd6afd9-4aa0-a5c9-ff0b3e60cdcf    node.js:16
^Object {data: Object, status: 200, headers: function, config: Object}
 config: Object
 data: Object
 Automation: Object
 Classification: Array[2]
 ExecutionTimestamp: "2014-08-13T16:08:37.4676Z"
 ID: "0fd6afd9-a5c9-ff0b3e60cdcf"
 Incident: Object
 LastStatus: "ENQUEUED"
 Metadata: Object
 Name: "Node Create"
 RecordLogs: false
 Source: "Device Lifecycle"
 Stream: Object
Targets: Array[1]

Upvotes: 0

Views: 3153

Answers (1)

bmleite
bmleite

Reputation: 26880

Make sure all your response interceptors return the data at the end:

Restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
  // your code here

  return data;
});

Not returning anything will set the data to undefined on following response interceptors calls.

Upvotes: 6

Related Questions