microsoftarchive / wunderlist.js

Wunderlist Javascript SDK
https://developer.wunderlist.com/documentation/tools/wunderlist.js
120 stars 29 forks source link

Unable to fetch lists #4

Closed xavdid closed 4 years ago

xavdid commented 8 years ago

Following the basic example I'm unable to get a result. I can't give more specific examples because there doesn't seem to be a way to surface error codes? Curiously, I can get a result using bare request (and curl). My code (running on an express server):

// doesn't work
var WunderlistSDK = require('wunderlist');
  var wunderlist = new WunderlistSDK({
    'accessToken': process.env.WUNDERLIST_ACCESS_TOKEN,
    'clientID': process.env.WUNDERLIST_CLIENT_ID
  });

  wunderlist.http.lists.all()
    .done(function (lists) {
      console.log(lists);
    })
    .fail(function () {
      console.error('there was a problem');
    });
// works fine
var request = require('request');
var options = {
  url: 'https://a.wunderlist.com/api/v1/lists',
  headers: {
    'X-Access-Token': process.env.WUNDERLIST_ACCESS_TOKEN,
    'X-Client-ID': process.env.WUNDERLIST_CLIENT_ID
  }
};

request(options, function(err, resp, body){
  var lists = JSON.parse(body); // is actually the error message in case of err
  if (!err && resp.statusCode === 200) 
    res.send(lists);
  } else {
    console.log('code: ',resp.statusCode);
    res.send(body);
  }
});

SDK version is 0.1.2. Any ideas? Let me know if I can provide any other info.

LoungeFlyZ commented 8 years ago

I am having the same problem :(

edit: bit more information. Tried this on node 0.12.9 and 5.4.

chad commented 8 years ago

@octatone can you take a look?

Sammons commented 8 years ago

@LoungeFlyZ saw your tweet and got curious ;)

Using https://github.com/driverdan/node-XMLHttpRequest version 1.6.0 seemed to fix it? (instead of ^1.6.0, which pulls in the latest non-2.* thing).

Reject is bound to 'error' here, which makes sense https://github.com/wunderlist/wunderlist.js/blob/master/public/io/IOBase.js#L194

but then xmlhttprequest appears to call abort() when opening the request https://github.com/driverdan/node-XMLHttpRequest/blob/554280a7c509c1ce4d7ad9516b46d182739e8026/lib/XMLHttpRequest.js#L157

which then (accidentally?) dispatches the 'abort' event as a side effect it looks xmlhttprequest didn't always dispatch the 'abort' event, it was introduced in September old: https://github.com/driverdan/node-XMLHttpRequest/blob/1.6.0/lib/XMLHttpRequest.js#L521 now: https://github.com/driverdan/node-XMLHttpRequest/commit/94a27f11bce860b280568dd5751a19125b45a3af

which then is treated like a failure https://github.com/wunderlist/wunderlist.js/blob/master/public/io/io/AjaxTransport.js#L257

which then invokes reject :( https://github.com/wunderlist/wunderlist.js/blob/master/public/io/io/AjaxTransport.js#L270

xavdid commented 8 years ago

That's frustrating! What's the best course of action? Locally we can adjust the dependencies with shrinkwrap, but we should also actually fix the issue. Do you want to do a new release that specifies 1.6.0 or change the code so that an error message is bubbled up when a request is rejected?

Sammons commented 8 years ago

@Xavdidtheshadow probably nothing needs to be changed in this repo (I'm new to this codebase)? Any patches would break proper behavior when .abort() is called normally. I would call it a bug that open always emits an abort event in the xmlhttprequest lib. Whatever they want that .abort() call to do could be refactored out into something else that's less of a trap? https://github.com/driverdan/node-XMLHttpRequest/blob/554280a7c509c1ce4d7ad9516b46d182739e8026/lib/XMLHttpRequest.js#L157

edit - went ahead and asked if they are doing it on purpose - https://github.com/driverdan/node-XMLHttpRequest/issues/125

octatone commented 8 years ago

I'll remove the ^ for now. This should be tied to specific dependencies not the loosey goosey ^ that keeps rearing its ugly head in many modules.