Error handling
- Error Response enhancement for Generic Error Messages
- How to handle errors from back-end in front-end and different languages?
- Mastering Error Handling: A Comprehensive Guide
- Error Handling in Backend Applications
- Analytics and monitoring: Proactive Error Handling with Real-Time Monitoring
- Reading material
Error Response enhancement for Generic Error Messages
Applications should not leak information about business logic to client applications. In order to achieve this, it is important to not leak any details about the inner workings of the application through error messages.
This is how to achieve it.
Description: As an API consumer, I want to receive generic error messages when an issue occurs, so that I don’t gain insight into the application’s internal workings or potential vulnerabilities, while still understanding that an error has occurred.
Acceptance Criteria:
- The API must return generic error messages for all unexpected exceptions.
- Specific error conditions (e.g., validation failures, authentication errors) should be handled by a global error handler that returns a predefined, non-descriptive error message to the client.
- The global error handler must include a catch-all mechanism for any unspecified exceptions, ensuring no detailed internal error information is exposed.
- Internal logging should capture detailed error information for debugging purposes, separate from the client response.
- Example
{ "error": "q" }
How to do this?
- Here is a simple way this can be done in golang by using a middleware function
- This makes it easy in the application code. Whenever we want to throw an error, just set it in c.Error(xxx) and return.
- The middleware function takes care of intercepting that and translating it further - if necessary
- https://gin-gonic.com/en/docs/examples/error-handling-middleware/
- Here is another way this is done.
- This does not use a middleware function.
- Instead, this uses a custom function and all the routes are wrapped by that custom function.
- https://boldlygo.tech/posts/2024-01-08-error-handling/
- Here is another example.
- Go Error Handling Techniques: Exploring Sentinel Errors, Custom Types, and Client-Facing Errors https://arashtaher.wordpress.com/2024/09/05/go-error-handling-techniques-exploring-sentinel-errors-custom-types-and-client-facing-errors/
How to handle errors from back-end in front-end and different languages?
Mastering Error Handling: A Comprehensive Guide
https://dev.to/kfir-g/mastering-error-handling-a-comprehensive-guide-1hmg
Error Handling in Backend Applications
Never throw Runtime exceptions without handling them
In backend development, error handling isn’t just about debugging; it’s about providing clear, actionable responses. Each type of error — whether it’s a system error, such as database connectivity issues, or an application error, like invalid user input — requires unique handling.
See Spring - exception handling
Centralized Error Logging
“Centralized logging creates a strong foundation for resilient applications by ensuring every error is tracked and recorded.”
Centralized error logging consolidates all errors in one place, making it easier to identify patterns and troubleshoot. Logging systems capture valuable data about when and where errors occur, supporting more informed and efficient debugging.
User-Friendly Error Messages
Poorly handled errors can drive users away. Rather than displaying vague “An error occurred” messages, user-friendly responses provide clarity, helping users understand the issue and often offering a next step.
Analytics and monitoring: Proactive Error Handling with Real-Time Monitoring
Real-time monitoring enables developers to catch and address errors before they escalate. With monitoring tools like Sentry and New Relic, you can set up alerts for real-time error tracking, allowing your team to resolve critical issues immediately. Real-time monitoring bridges frontend and backend error reporting, providing a holistic view of your application’s performance.
Use analytics and monitoring tools to track and analyze error logs. This helps us identify patterns and trends, allowing us to proactively address recurring issues and make improvements to the system.
If you’re building full-stack applications, real-time monitoring is an invaluable tool that integrates seamlessly across systems.
Reading material
- How do you handle error handling and logging in backend systems? https://gtcsys.com/faq/how-do-you-handle-error-handling-and-logging-in-backend-systems/
- Go’s Error Handling Is a Form of Storytelling https://preslav.me/2023/04/14/golang-error-handling-is-a-form-of-storytelling/