janmonschke / backbone-couchdb

A couchdb connector for backbone with support for real time changes.

Home Page:http://janmonschke.com/projects/backbone-couchdb.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with the error handler on update error

nicogranelli opened this issue · comments

I'm using this project for the first time. This are the steps to reproduce the error:

  1. fetch a model
  2. change the model in futon (to trigger an error for conflict)
  3. save the model
  4. the error callback is called, but with wrong arguments. I used a console.log(arguments) inside the callback, and I get these 3:
  • The model
  • undefined
  • and Object with success and error, both functions

According to http://documentcloud.github.com/backbone/#Model-save, the error callback should get the model and the response.

NOTE: Maybe this is because couchdb, and response can't be returned, I'm not sure, I don't know this project or couchdb well enough to be sure.

PD: Do you need an unit test showing the error? I can try to write a jasmine showing it

That would be handy!

I'm having the same problem. How do I get access to the actual error that was thrown during a save() ?

Digging into it right now

Unfortunately there's no way to access the response itself since jquery.couch.js does not pass it to the error-callback. But I added a new object that will be passed to error-callbacks that accumulates at least some information on the request.

A simple example for an error callback for a non-existing model:

myModel.fetch({error: function(model, req, options){
    console.log(model, req, options);
}});

This would lead to the following console output:

Screenshot

Is this sufficient enough?

sorry for the late response, I always miss github notifications.

Backbone return the response so the user could check the error, so returning the error instead is pretty close.

Thanks!