So far, we have not paid great attention to the errors that can occur in our applications.
Under normal operation, most application calls will not result in an exception. But there are valid reasons why an exception might be thrown:
- Input validation
For example, we may want to validate user inputs, such as valid JSON request body, or valid query parameter values. Example: non empty list, string, valid email address, etc. - State validation
For example, we may want to validate the state of the application, such as whether a user is logged in, or whether a resource exists. - Business logic validation
For example, we may want to validate the business logic of the application, such as whether a user has permission to perform an action, or whether a resource is available.
You also need to account for unexpected errors, such as network failures, database errors, or other unforeseen issues, as well as third-party (library, service) failures.