Reputation: 2523
I'm getting a 500 server error in the console when trying to update a record from an http-mock generated in ember-cli.
Here is what I'm trying to do
model: function(params) {
return this.store.find('user', params.pin);
},
actions: {
check_out: function(checkedUser) {
var model = this.modelFor(this.routeName);
model.set('checked_in',false);
model.save().then(function(){
self.transitionTo('volunteer-check-out-success');
});
}
}
but I'm receiving this error in the console
PUT http://localhost:4200/api/users/2 500 (Internal Server Error)
the get request works just fine so it's odd that I'm getting 500 with the put request.
Does anyone have a good overview of how to use http-mock? Maybe even in it's earlier stages before it was called http-mock? I'm still a little confused on how this works inside of ember-cli and documentation and examples are kind of sparse from what I've been finding. And I think reading up on some info on how this works in theory would help me troubleshoot it on my own.
UPDATE:
Here is the server implementation, I have this variable that the get request is reading from
var USERS = [
{
"id": 1,
"checked_in": false,
"pin": 1234,
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"phone": 8436376960
},
{
"id": 2,
"checked_in": false,
"pin": 5678,
"first_name": "Jane",
"last_name": "Smith",
"email": "[email protected]",
"phone": 8436375738
}
];
And my put route handler like so
usersRouter.put('/:id', function(req, res) {
var id = req.params.id;
var user = USERS.filter(function(user) {
return user.id.toString() == id;
})[0];
user.checked_in = req.body.checked_in;
user.pin = req.body.pin;
user.first_name = req.body.first_name;
user.last_name = req.body.last_name;
user.email = req.body.email;
user.phone = req.body.phone;
return res.send(user);
});
Upvotes: 1
Views: 814
Reputation: 47367
I've never used it, but if it's anything like the majority of the ajax mocking tools out there, you'll need to setup routes to handle different endpoints and also to handle different verbs (GET/POST).
In your case I'd guess your original route setup handles the /projects/
endpoint for the GET
verb, whereas when you save it `
Upvotes: 1