improved error logging to the db