Improve logging when db query fails