···
"Coves/internal/core/votes"
···
// handleServiceError converts service errors to appropriate HTTP responses
// Error names MUST match lexicon definitions exactly (UpperCamelCase)
31
+
// Uses errors.Is() to handle wrapped errors correctly
func handleServiceError(w http.ResponseWriter, err error) {
32
-
case votes.ErrVoteNotFound:
34
+
case errors.Is(err, votes.ErrVoteNotFound):
// Matches: social.coves.feed.vote.delete#VoteNotFound
writeError(w, http.StatusNotFound, "VoteNotFound", "No vote found for this subject")
35
-
case votes.ErrSubjectNotFound:
37
+
case errors.Is(err, votes.ErrSubjectNotFound):
// Matches: social.coves.feed.vote.create#SubjectNotFound
writeError(w, http.StatusNotFound, "SubjectNotFound", "The subject post or comment was not found")
38
-
case votes.ErrInvalidDirection:
40
+
case errors.Is(err, votes.ErrInvalidDirection):
writeError(w, http.StatusBadRequest, "InvalidRequest", "Vote direction must be 'up' or 'down'")
40
-
case votes.ErrInvalidSubject:
42
+
case errors.Is(err, votes.ErrInvalidSubject):
// Matches: social.coves.feed.vote.create#InvalidSubject
writeError(w, http.StatusBadRequest, "InvalidSubject", "The subject reference is invalid or malformed")
43
-
case votes.ErrVoteAlreadyExists:
45
+
case errors.Is(err, votes.ErrVoteAlreadyExists):
writeError(w, http.StatusConflict, "AlreadyExists", "Vote already exists")
45
-
case votes.ErrNotAuthorized:
47
+
case errors.Is(err, votes.ErrNotAuthorized):
// Matches: social.coves.feed.vote.create#NotAuthorized, social.coves.feed.vote.delete#NotAuthorized
writeError(w, http.StatusForbidden, "NotAuthorized", "User is not authorized to vote on this content")
48
-
case votes.ErrBanned:
50
+
case errors.Is(err, votes.ErrBanned):
writeError(w, http.StatusForbidden, "NotAuthorized", "User is not authorized to vote on this content")
// Internal server error - log the actual error for debugging