chore(release): snapshot 1.4.2
This commit is contained in:
@@ -46,20 +46,26 @@ func (h *PlanHandler) CreatePlan(w http.ResponseWriter, r *http.Request) {
|
||||
var req domain.CreatePlanRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
log.Printf("❌ Invalid request body: %v", err)
|
||||
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Invalid request body", "message": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
plan, err := h.planService.CreatePlan(&req)
|
||||
if err != nil {
|
||||
log.Printf("❌ Error creating plan: %v", err)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch err {
|
||||
case service.ErrPlanSlugTaken:
|
||||
http.Error(w, err.Error(), http.StatusConflict)
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Slug already taken", "message": err.Error()})
|
||||
case service.ErrInvalidUserRange:
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Invalid user range", "message": err.Error()})
|
||||
default:
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Internal server error", "message": err.Error()})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user