Strengthened middleware to gracefully handle errors