No software product is perfect, and the harsh truth is that no matter how much effort you put into designing and testing your code, there is always a very good chance that you missed some edge case that will cause your application to fail. If you can't win the game, you need to change the rules. Instead, make sure that, even if your application fails with an error, it will know how to recover and give you as much information as it can so that you can reproduce the scenario and solve the problem.
In this chapter, you will learn how you can protect your API from unhandled exceptions, and how you can return meaningful error responses to your API client that will later allow you to decipher what the problem was. You will also learn how to add logging and diagnostics to your code, so that problem investigation will become easier.
In...