Skip to content

Instantly share code, notes, and snippets.

@jakecraige
Last active August 29, 2015 14:03
Show Gist options
  • Save jakecraige/310a8933f7f962bbe8e6 to your computer and use it in GitHub Desktop.
Save jakecraige/310a8933f7f962bbe8e6 to your computer and use it in GitHub Desktop.
import icAjax from 'ic-ajax';
// ...
authenticate: function() {
var request = icAjax(this.get('createSessionUrl'), {
method: 'POST',
dataType: 'json',
data: JSON.stringify(data),
contentType: 'application/json'
});
var session = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
request.then(function(userData){
session.save(userData);
session.setPrefilter();
resolve(userData);
}, function(err){
console.log('Authentication error: ', err);
reject(err);
});
});
}
// test
session.authenticate('example@example.com', 'password').then(function() {}, function() {
// If I don't wrap the ic-ajax request in RSVP.Promise, it will always resolve successfully
// when I chain something on to it, even though internally it's rejected.
// (I see the console log on LN18)
//
// When I wrap it, this test passes
ok('Promise rejected')
start();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment