Better error handling in Gateway