summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2025-02-01 20:45:30 -0500
committerRobby Zambito <contact@robbyzambito.me>2025-02-09 17:06:19 -0500
commit32c110edfb97abce50ed1d57e529cb7eda2428dd (patch)
treea4cc51b42467b5616a81f3cb050106046a657738
parent7101dd003be4b85ac57b387998d22cc6eaf4aa51 (diff)
Use 404 when there are no NATS handlers
-rw-r--r--main.go8
1 files changed, 7 insertions, 1 deletions
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
}