Added support for onFailure hooks

Useful to cleanup database connections after a fatal error.
Merge pull request #43 from Vektah/master

Add onFailure hooks