tutorials/6.errors.md
`catch` block should be provided for every async operation or group of async operations:
````javascript
User.create({email: 'example@example.com'}).then(function(user) {
user.email = 'example2@example.com';
return user.save();
}).catch(StorageError, function(err) {
console.log('An storage error occured while saving user instance, code: ' + err.code);
}).catch(function(err) {//Always provide at least one "global" catch block
//
});
````
Note that CouchbaseODM mirrors storage error codes from official nodejs couchbase sdk.
`Promise.error` should not be used because it handles only asynchronously returned errors:
````javascript
User.create({email: 'example@example.com'}).then(function(user) {
throw new Error('test');
}).error(function(err) { // Don't do that, the Error('test') wont be catched here
//
});
````