Created
November 17, 2011 22:08
-
-
Save Raynos/1374703 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var whitelistMap = { | |
"get": ["not_found"], | |
"insert": ["conflict"], | |
"delete": [] | |
} | |
function makeWhitelistCallback(method, thing, cb) { | |
return error.whitelist(function _errors(err) { | |
if (err.syscall === "getaddrinfo") { | |
UserModel[method](thing, cb); | |
} else if (whitelistMap[method].indexOf(err.error) !== -1) { | |
return true; | |
} else { | |
return false; | |
} | |
}, cb); | |
} | |
var UserModel = pd.make(Model,{ | |
get: function _get(id, cb) { | |
this.nano.get(id, | |
makeWhitelistCallback("get", id, cb) | |
); | |
}, | |
insert: function _create(json, cb) { | |
this.nano.insert(json, json._id, | |
makeWhitelistCallback("insert", json, cb) | |
); | |
}, | |
delete: function _delete(name, cb) { | |
var that = this; | |
this.get(name, function _getRev(err, body) { | |
that.nano.destroy(name, body._rev, | |
makeWhitelistCallback("delete", name, cb) | |
); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment