Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with PromiseProxyMixin: Uncaught [object Object] and .catch is not a function #13750

Closed
caseklim opened this issue Jun 24, 2016 · 3 comments

Comments

@caseklim
Copy link

Using this example from the guides, I would expect the error to be caught as reason (since "/some/remote/data.json" is obviously invalid):

var ObjectPromiseProxy = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin);

var proxy = ObjectPromiseProxy.create({
  promise: Ember.$.getJSON('/some/remote/data.json')
});

proxy.then(function(json) {
  // the json
}, function(reason) {
  // the reason why you have no json
});

Instead, the full error message is printed to the console, as well as Uncaught [object Object]. Is this documentation out of date, or is there an issue with PromiseProxyMixin?

Another related issue is that using the following code instead yields the error Uncaught TypeError: proxy.then(...).catch is not a function:

proxy.then(function(json) {
  // the json
}).catch(function (reason) {
  // the reason why you have no json
});

Guide for reference:
http://emberjs.com/api/classes/Ember.PromiseProxyMixin.html

I'm using Ember 2.6.0, and encountered the same issues at https://ember-twiddle.com/

@chadhietala
Copy link
Contributor

@cklimkowsky I think this is because Ember.$.getJSON() does not return a ECMA specified promise, it's going to return a jquery Defered which is non-spec compliant. You should cast the jQuery deferred to a spec compliant promise.

const { cast } = Ember.RSVP; 
var proxy = ObjectPromiseProxy.create({
  promise: cast(Ember.$.getJSON('/some/remote/data.json'))
});

@mixonic
Copy link
Member

mixonic commented Jun 26, 2016

The documentation should definitely be updated here. Perhaps simplest is to change the docs away from using a raw jQuery deferred.

However we should also confirm that the casted jQuery promise does the correct thing.

@habdelra
Copy link
Contributor

habdelra commented Jun 26, 2016

Here is a twiddle that shows @chadhietala 's example works correctly in the example above: https://ember-twiddle.com/55ae031da0bfe8647440410ce9016d67

I'll update the docs to reflect this.

rwjblue added a commit that referenced this issue Jun 27, 2016
Fixes #13750 update documentation to cast `getJSON` to compliant promise
toddjordan pushed a commit to toddjordan/ember.js that referenced this issue Sep 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants