-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Labels
area:control-planeControl plane server functionalityControl plane server functionalitygood first issueGood for newcomersGood for newcomersrefactorCode quality and refactoring improvementsCode quality and refactoring improvements
Description
Summary
Multiple handler files define similar ErrorResponse structs and error handling patterns. Extract these to a shared location to reduce duplication.
Current State
- Issue:
ErrorResponsestruct 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.gowith shared types/functions - Update existing handlers to use shared error utilities
- Remove duplicate
ErrorResponsedefinitions
Acceptance Criteria
- Shared error file created
- At least 3 handler files updated to use shared utilities
- No duplicate
ErrorResponsestruct definitions remain - All tests pass
- Code compiles without errors
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:control-planeControl plane server functionalityControl plane server functionalitygood first issueGood for newcomersGood for newcomersrefactorCode quality and refactoring improvementsCode quality and refactoring improvements