Getting errors in callbacks
If I call a method in lownchair and its errors, can I get the error callback? I am implementing an adapter and have some known error conditions that I would like to expose to the client to handle. But I cannot find out how errors are returned to the API. Are they node styled? eg: callback (error, result) where error = null in case of no errors or something else?
source to share
Short answer: Lunchar adapter methods don't make any major mistakes. The client will get an exception if something particularly bad happens in the adapter.
Below is the code for the save method of the DOM adapter - it's clear that if something bad happens, the callback will not be called at all; application code has to deal with the exception.
save: function (obj, callback) {
var key = obj.key ? this.name + '.' + obj.key : this.name + '.' + this.uuid()
// if the key is not in the index push it on
if (this.indexer.find(key) === false) this.indexer.add(key)
// now we kil the key and use it in the store colleciton
delete obj.key;
storage.setItem(key, JSON.stringify(obj))
obj.key = key.slice(this.name.length + 1)
if (callback) {
this.lambda(callback).call(this, obj)
}
return this
},
You can of course do internal error handling in your adapter and pass an additional parameter for the callback. This will cause your adapter to behave inconsistently with the rest of the adapters, which could be a disadvantage.
I suggest that your adapter throws an exception like other adapters do, unless it's impossible to recover from an error inside the adapter.
source to share