1
votes

i get this typeerror in my response, and i don't know, what format store.find('someThread') expects. here is my ember-part:

App.RestAdapter = DS.RESTAdapter.extend({
  url: 'http://mylocalhost:3000',
  namespace: 'api',

  serializer: DS.RESTSerializer.extend({
    primaryKey: function(type) {
        return '_id';
    }
  })
});

App.Store = DS.Store.extend({
  revision: 12,
  adapter: App.RestAdapter
});

App.VideoRoute = Ember.Route.extend({
  model: function() {
    console.log("video..", this.store.find('video'));
    return true;
  }
});

And here's the node-part:

exports.list = function(req, res) {
  Video.find(function(err, videos) {
    var payload = { video: {name: "sampleName"}};
    return res.send(200, JSON.stringify(payload));
  });
}

And here is the console.log of the response:

Class {constructor: function, reason: null, isPending: undefined, isSettled: undefined, isRejected: false…}
  __ember1385638132476: undefined
  __ember1385638132476_meta: Meta
  _super: undefined
  arrangedContent: (...)
  content: (...)
  isRejected: true
  reason: TypeError
  message: "Object function () {↵    if (!wasApplied) {↵  (...)"
  stack: (...)
  get stack: function () { [native code] }
  set stack: function () { [native code] }
  __proto__: Error
  __proto__: Object

i do get a response if i just send a string: `res.send("something"); but that's just in the responseText, and isRejected is true, so...

any ideas?

UPDATE

*Here is the truncated message part: *

"Object function () {
if (!wasApplied) {
  Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
var m = meta(this), proto = m.proto;
m.proto = this;
if (initMixins) {
  // capture locally so we can clear the closed over variable
  var mixins = initMixins;
  initMixins = null;
  this.reopen.apply(this, mixins);
}
if (initProperties) {
  // capture locally so we can clear the closed over variable
  var props = initProperties;
  initProperties = null;

  var concatenatedProperties = this.concatenatedProperties;

  for (var i = 0, l = props.length; i < l; i++) {
    var properties = props[i];

    Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin));

    if (properties === null || typeof properties !== 'object') {
      Ember.assert("Ember.Object.create only accepts objects.");
      continue;
    }

    var keyNames = Ember.keys(properties);
    for (var j = 0, ll = keyNames.length; j < ll; j++) {
      var keyName = keyNames[j];
      if (!properties.hasOwnProperty(keyName)) { continue; }

      var value = properties[keyName],
          IS_BINDING = Ember.IS_BINDING;

      if (IS_BINDING.test(keyName)) {
        var bindings = m.bindings;
        if (!bindings) {
          bindings = m.bindings = {};
        } else if (!m.hasOwnProperty('bindings')) {
          bindings = m.bindings = o_create(m.bindings);
        }
        bindings[keyName] = value;
      }

      var desc = m.descs[keyName];

      Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty));
      Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1));
      Ember.assert("`actions` must be provided at extend time, not at create time, when Ember.ActionHandler is used (i.e. views, controllers & routes).", !((keyName === 'actions') && Ember.ActionHandler.detect(this)));

      if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) {
        var baseValue = this[keyName];

        if (baseValue) {
          if ('function' === typeof baseValue.concat) {
            value = baseValue.concat(value);
          } else {
            value = Ember.makeArray(baseValue).concat(value);
          }
        } else {
          value = Ember.makeArray(value);
        }
      }

      if (desc) {
        desc.set(this, keyName, value);
      } else {
        if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) {
          this.setUnknownProperty(keyName, value);
        } else if (MANDATORY_SETTER) {
          Ember.defineProperty(this, keyName, null, value); // setup mandatory setter
        } else {
          this[keyName] = value;
        }
      }
    }
  }
}
finishPartial(this, m);
this.init.apply(this, arguments);
m.proto = proto;
finishChains(this);
sendEvent(this, "init");
} has no method 'extract'"

UPDATE2:

found out you can override the ajax-method. now, at least i know, that the json IS beeing transmitted on the success-function, but the data-property is still undefined...

App.ApplicationAdapter = DS.RESTAdapter.extend({
  url: 'http://localhost:3000',
  namespace: 'api',

  ajax: function(url, type, hash) {
   var adapter;
   adapter = this;
   return new Ember.RSVP.Promise(function(resolve, reject) {
    var headers;
    hash = hash || {};
    hash.url = url;
    hash.type = type;
    hash.dataType = "json";
    hash.context = adapter;
    if (hash.data && type == "GET") {
      hash.contentType = "application/json; charset=utf-8";
      hash.data = JSON.stringify(hash.data);
    }
    if (adapter.headers !== undefined) {
      headers = adapter.headers;
      hash.beforeSend = function(xhr) {
        return forEach.call(Ember.keys(headers), function(key) {
          return xhr.setRequestHeader(key, headers[key]);
        });
      };
    }
    hash.success = function(json) {
      console.log("success", hash.data, json); //-> undefined, Object {video: Object}
      return Ember.run(null, resolve, json);
    };
    hash.error = function(jqXHR, textStatus, errorThrown) {
      return Ember.run(null, reject, adapter.ajaxError(jqXHR));
    };
    return Ember.$.ajax(hash);
  });
 },
});
1
Can you show what appears in the message property. Your stacktrace show it truncated probably the message show "Object function () {↵ if (!wasApplied) {↵ ... doesn't have method foo" etc. And this could help. - Marcio Junior
thx @MárcioRodriguesCorreaJúnior, updated the post. i have to say, i'm new to this backend stuff. i usually work without ember-data. - user3045673
What is your ember-data version? - Marcio Junior
ember is 1.2.0 and ember-data is 1.0.0 beta 3 - user3045673

1 Answers

1
votes

If you are using the ember-data 1.0.0-beta.x version you need to declare your adapter and serializer like the following:

App.ApplicationSerializer = DS.RESTSerializer.extend({
  primaryKey: '_id'
});

App.ApplicationAdapter = DS.RESTAdapter.extend({
  url: 'http://mylocalhost:3000',
  namespace: 'api'
});

App.VideoRoute = Ember.Route.extend({
  model: function() {
    console.log("video..", this.store.find('video'));
    return true;
  }
});

There is a transition guide here, that tells what is the changes between 0.13 and 1.0.0-beta.x versions