lundi 21 septembre 2015

ember http-mock returning 304

I am using ember-cli and ember-data 1.13.7 and JSONAPIAdapter. I use http-mock to mock data during local testing. It worked well when I used the RESTAdapter, but I ran into a problem when switching to the JSONAPIAdapter.

The problem is that http-mock is returning a status of 304 ("Not Modified") when the adapter asks for a record. Then the records data does not get loaded into the store and I get an error reading an undefined property.

The adpater just looks like this:

import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
    namespace: 'api',
});

The ajax call is this:

http://localhost:4200/api/users/1

The http-mock looks like this:

usersRouter.get('/:id', function(req, res) {
 res.send({
  'users': {
    id: req.params.id,
    firstname: "John",
    lastname: "Doe",
    email: "johndoe@example.com",
    mobile: "12345678",
    nextAppointment: 1
  }
 });
});

The response looks like this:

{"users":{"id":"1","firstname":"John","lastname":"Doe","email":"johndoe@example.com","mobile":"12345678","nextAppointment":1}}

The response data islooking good but the problem is that together with the response is the header status code of 304, and the fact that the data is not loaded into store. The object with id=1 is created, but all properties in the object are 'undefined' when I look at the stores data in the ember inspector.

Update:

The error I get is:

Error while processing route: 
    home.index Cannot read property '_internalModel' of undefined 
    TypeError: Cannot read property '_internalModel' of undefined




Aucun commentaire:

Enregistrer un commentaire