mercredi 26 août 2015

Error returning promise from Ember Data

I am working on my first Ember app and got it to display as I wanted with the route returning a static JSON object for the model. Now I am trying to refactor to use Ember Data + Mirage and having an awful time.

Good news is that if in the route's model function I try this:

console.log(this.store.find('element', 1));

I see in the console that the request was successful, and the correct object is displayed. (Though note that the Ember inspector, under Data, shows me the object with id = 1 but the key is undefined rather than having the correct value I see in the console.)

The bad news is that if in the model() function I try:

return this.store.find('element', 1);

the app doesn't render at all and I get:

22:46:40.883 "Error while processing route: index" "Assertion Failed: normalizeResponse must return a valid JSON API document:
    * One or more of the following keys must be present: "data", "errors", "meta"." "EmberError@http://localhost:4200/assets/vendor.js:25582:15
_emberMetalCore.default.assert@http://localhost:4200/assets/vendor.js:15745:13
ember$data$lib$system$store$serializer$response$$normalizeResponseHelper@http://localhost:4200/assets/vendor.js:123912:1
ember$data$lib$system$store$finders$$_find/</<@http://localhost:4200/assets/vendor.js:124107:25
Backburner.prototype.run@http://localhost:4200/assets/vendor.js:10838:18
ember$data$lib$system$store$$Store<._adapterRun@http://localhost:4200/assets/vendor.js:129461:16
ember$data$lib$system$store$finders$$_find/<@http://localhost:4200/assets/vendor.js:124106:1
tryCatch@http://localhost:4200/assets/vendor.js:60829:14
invokeCallback@http://localhost:4200/assets/vendor.js:60844:15
publish@http://localhost:4200/assets/vendor.js:60812:9
@http://localhost:4200/assets/vendor.js:40152:7
Queue.prototype.invoke@http://localhost:4200/assets/vendor.js:11532:9
Queue.prototype.flush@http://localhost:4200/assets/vendor.js:11596:11
DeferredActionQueues.prototype.flush@http://localhost:4200/assets/vendor.js:11392:11
Backburner.prototype.end@http://localhost:4200/assets/vendor.js:10720:9
Backburner.prototype.run@http://localhost:4200/assets/vendor.js:10842:13
run@http://localhost:4200/assets/vendor.js:29656:12
ember$data$lib$adapters$rest$adapter$$RESTAdapter<.ajax/</hash.success@http://localhost:4200/assets/vendor.js:122361:15
jQuery.Callbacks/fire@http://localhost:4200/assets/vendor.js:3350:10
jQuery.Callbacks/self.fireWith@http://localhost:4200/assets/vendor.js:3462:7
done@http://localhost:4200/assets/vendor.js:9516:5
.send/callback@http://localhost:4200/assets/vendor.js:9920:8
_readyStateChange@http://localhost:4200/assets/vendor.js:64353:9
_setResponseBody@http://localhost:4200/assets/vendor.js:64419:9
respond@http://localhost:4200/assets/vendor.js:64440:7
handleRequest/<@http://localhost:4200/assets/vendor.js:65413:11
resolve@http://localhost:4200/assets/vendor.js:65450:9
handleResponse/<@http://localhost:4200/assets/vendor.js:65441:11
"1 vendor.js:38337:5
logError() vendor.js:38337
defaultActionHandlers.error() vendor.js:38280
triggerEvent() vendor.js:38391
trigger() vendor.js:60414
Transition.prototype.trigger() vendor.js:60228
Transition/this.promise<() vendor.js:60048
tryCatch() vendor.js:60829
invokeCallback() vendor.js:60844
publish() vendor.js:60812
publishRejection() vendor.js:60747
<anonymous> vendor.js:40152
Queue.prototype.invoke() vendor.js:11532
Queue.prototype.flush() vendor.js:11596
DeferredActionQueues.prototype.flush() vendor.js:11392
Backburner.prototype.end() vendor.js:10720
Backburner.prototype.run() vendor.js:10842
run() vendor.js:29656
ember$data$lib$adapters$rest$adapter$$RESTAdapter<.ajax/</hash.success() vendor.js:122361
jQuery.Callbacks/fire() vendor.js:3350
jQuery.Callbacks/self.fireWith() vendor.js:3462
done() vendor.js:9516
.send/callback() vendor.js:9920
_readyStateChange() vendor.js:64353
_setResponseBody() vendor.js:64419
respond() vendor.js:64440
handleRequest/<() vendor.js:65413
resolve() vendor.js:65450
handleResponse/<() vendor.js:65441




Aucun commentaire:

Enregistrer un commentaire