Reporting errors with JSON
There are many ways to handle errors when writing web applications. In our sample application, we handle errors to inform users of what’s happening with their request. When reporting errors to users about their request, remember not to expose too much information about what’s happening to the system. The following are some examples of error messages reported to users that contain such information:
- There is a connection error to the database
- The username and password are not valid for connecting to the database
- Username validation failed
- The password cannot be converted to plain text
The preceding JSON error use cases are normally used in scenarios where more information needs to be provided to the frontend to inform users. Simpler error messages containing error codes can also be used.
Using JSONError
Standardizing error messages is as important as writing proper code to ensure application maintainability. At...