Search code examples
javascriptember.jsbrowserember-data

Ember-DS queryRecord returns TypeError: Cannot convert undefined or null to object


I'm trying to do a queryRecord search inside of my model function and I seem to be hitting an error:

TypeError: Cannot convert undefined or null to object

My model() looks like the following:

model() {
  return this.store.queryRecord('model', { property: 'value' })
    .then(doc => console.log(doc)) // This doesn't even invoke
}

Solution

  • The reason for this error is due to the XHR or REST API returning null or undefined as the response instead of an empty Object or Array.

    > GET /model?query=x
    < null
    

    should be

    > GET /model?query=x
    < {}