From 32c110edfb97abce50ed1d57e529cb7eda2428dd Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sat, 1 Feb 2025 20:45:30 -0500 Subject: Use 404 when there are no NATS handlers --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d0479e6..abadcc8 100644 --- a/main.go +++ b/main.go @@ -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 } -- cgit