Error handling +recording errors in db