Use 404 when there are no NATS handlers

This commit is contained in:
2025-02-01 20:45:30 -05:00
parent 7101dd003b
commit 32c110edfb

View File

@@ -120,8 +120,14 @@ func main() {
// Send the NATS request and wait synchronously for a reply (timeout: 30 seconds)
reply, err := nc.RequestMsg(&msg, 30*time.Second)
if err != nil {
http.Error(w, "Error processing request", http.StatusInternalServerError)
log.Println("NATS request error:", err)
// Handle specific NATS error cases
if err == nats.ErrNoResponders || strings.Contains(err.Error(), "no responders") {
http.Error(w, "No service available to handle request", http.StatusNotFound)
} else {
http.Error(w, "Error processing request", http.StatusInternalServerError)
}
return
}