Error Handling
Asset Reality’s coding standards enforce robust error handling practices across all backend services. This ensures that improper error handling, such as exposing sensitive information or unhandled exceptions, is avoided.
-
Structured Error Types
The platform defines centralised, reusable error types in a shared Errors package. Errors includes a consistent structure with HTTP status codes and safe, user-facing messages.
-
Safe API Responses
Error responses returned to clients avoid exposing internal stack traces or Go error messages. Handlers use typed error wrappers to return sanitised messages and appropriate status codes.
-
Centralised Panic Recovery The platform makes use of the chi router package and uses Chi’s
Recoverermiddleware to catch panics and prevent application crashes. Unexpected issues are intercepted and transformed into safe 500 responses. -
External Error Reporting
Errors are logged using
logrus.WithError(err)across handlers and middleware. These logs are forwarded to the logging service and to Datadog. This ensures that all unexpected behaviors, including panics and internal errors, are observable and can trigger alerts through Datadog’s log management system. -
Consistent Use Across Services These error handling strategies are applied across services, providing consistent behavior and observability.