Summary
Multiple handler files define similar ErrorResponse structs and error handling patterns. Extract these to a shared location to reduce duplication.
Current State
- Issue:
ErrorResponse struct and similar error patterns repeated across 10+ handler files
- Example location:
control-plane/internal/handlers/memory.go (lines 52-57)
Current Pattern (Duplicated)
// Found in multiple files:
type ErrorResponse struct {
Error string \`json:"error"\`
}
// Error response code duplicated:
c.JSON(http.StatusBadRequest, ErrorResponse{Error: "invalid request"})
Proposed Solution
Create a shared error utilities file:
// control-plane/internal/handlers/errors.go
package handlers
// ErrorResponse is the standard error response format.
type ErrorResponse struct {
Error string \`json:"error"\`
Code string \`json:"code,omitempty"\`
Details string \`json:"details,omitempty"\`
}
// RespondError sends a JSON error response with the given status code.
func RespondError(c *gin.Context, status int, message string) {
c.JSON(status, ErrorResponse{Error: message})
}
// RespondBadRequest sends a 400 Bad Request error response.
func RespondBadRequest(c *gin.Context, message string) {
RespondError(c, http.StatusBadRequest, message)
}
// RespondNotFound sends a 404 Not Found error response.
func RespondNotFound(c *gin.Context, message string) {
RespondError(c, http.StatusNotFound, message)
}
// RespondInternalError sends a 500 Internal Server Error response.
func RespondInternalError(c *gin.Context, message string) {
RespondError(c, http.StatusInternalServerError, message)
}
Tasks
- Create
control-plane/internal/handlers/errors.go with shared types/functions
- Update existing handlers to use shared error utilities
- Remove duplicate
ErrorResponse definitions
Acceptance Criteria
Files
control-plane/internal/handlers/errors.go (new)
- Multiple handler files to update
Using AI to solve this issue? Read our AI-Assisted Contributions guide for testing requirements, prompt strategies, and common pitfalls to avoid.
Summary
Multiple handler files define similar
ErrorResponsestructs and error handling patterns. Extract these to a shared location to reduce duplication.Current State
ErrorResponsestruct and similar error patterns repeated across 10+ handler filescontrol-plane/internal/handlers/memory.go(lines 52-57)Current Pattern (Duplicated)
Proposed Solution
Create a shared error utilities file:
Tasks
control-plane/internal/handlers/errors.gowith shared types/functionsErrorResponsedefinitionsAcceptance Criteria
ErrorResponsestruct definitions remainFiles
control-plane/internal/handlers/errors.go(new)