Skip to content

Commit eea4cca

Browse files
Added error handling for json encoder
1 parent 7fe2d1b commit eea4cca

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/search/handlers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ func SearchUsersHandler(w http.ResponseWriter, r *http.Request) {
2121
}
2222

2323
w.Header().Set("Content-Type", "application/json")
24-
json.NewEncoder(w).Encode(users)
24+
if err := json.NewEncoder(w).Encode(users); err != nil {
25+
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
26+
return
27+
}
2528
}

0 commit comments

Comments
 (0)