From 1ddf35e212386148abc05125e484563390ab37b5 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 10 Dec 2022 19:47:33 +0100 Subject: [PATCH] cmd/noxy: respond with appropriate status 5xx on context errors --- cmd/noxy/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/noxy/main.go b/cmd/noxy/main.go index 7047835..5516286 100644 --- a/cmd/noxy/main.go +++ b/cmd/noxy/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "errors" "flag" @@ -197,6 +198,8 @@ func writeError(w http.ResponseWriter, err error) { w.WriteHeader(http.StatusBadRequest) case errors.Is(err, noxy.ErrNotFound): w.WriteHeader(http.StatusNotFound) + case errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled): + w.WriteHeader(http.StatusServiceUnavailable) } fmt.Fprint(w, err.Error()) }