Improved the db error handling