daleharvey/jquery.couch.js — pull request #6 by algesten (2012-02-09 02:20:08+00:00)
Title: Fix for npe in error handler (resp is null)

The following code:

db.saveDoc(window.jsonModel, {
success: function (data) {
...
},
timeout: 10000,
error: function (xhr, textStatus, errorThrown) {
console.warn(xhr, textStatus, errorThrown);
_this.handleSaveError();
});

I can make fail every time. I just ctrl-c my local couchdb instance just before executing the above lines and I get a `resp is null`.

The problem occurs when jquery.couch.js is about to call my error handler (I never reach my handler):

} else if (options.error) {
options.error(req.status, resp.error, resp.reason);

`resp` is in these cases not a JSON object, but null.

I've applied defensive fixes wherever I found the above rows.