diff --git a/api/handler/http/http.go b/api/handler/http/http.go index 5accfab3..7de8b518 100644 --- a/api/handler/http/http.go +++ b/api/handler/http/http.go @@ -28,7 +28,7 @@ type httpHandler struct { func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { service, err := h.getService(r) if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) return } @@ -39,7 +39,7 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { rp, err := url.Parse(service) if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) return } diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 17c4b37e..0ab59c70 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -428,11 +428,11 @@ func writeError(w http.ResponseWriter, r *http.Request, err error) { switch ce.Code { case 0: // assuming it's totally screwed - ce.Code = 500 + ce.Code = http.StatusInternalServerError ce.Id = "go.micro.api" - ce.Status = http.StatusText(500) + ce.Status = http.StatusText(http.StatusInternalServerError) ce.Detail = "error during request: " + ce.Detail - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) default: w.WriteHeader(int(ce.Code)) } diff --git a/broker/http/http.go b/broker/http/http.go index 2b59de5b..052e8fbe 100644 --- a/broker/http/http.go +++ b/broker/http/http.go @@ -283,7 +283,7 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) { b, err := ioutil.ReadAll(req.Body) if err != nil { errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err) - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(errr.Error())) return } @@ -291,7 +291,7 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) { var msg *broker.Message if err = h.opts.Codec.Unmarshal(b, &msg); err != nil { errr := merr.InternalServerError("go.micro.broker", "Error parsing request body: %v", err) - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(errr.Error())) return } @@ -300,7 +300,7 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) { if len(topic) == 0 { errr := merr.InternalServerError("go.micro.broker", "Topic not found") - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(errr.Error())) return } diff --git a/client/retry.go b/client/retry.go index e23dc1aa..217a50e8 100644 --- a/client/retry.go +++ b/client/retry.go @@ -2,6 +2,7 @@ package client import ( "context" + "net/http" "github.com/micro/go-micro/v3/errors" ) @@ -27,7 +28,7 @@ func RetryOnError(ctx context.Context, req Request, retryCount int, err error) ( switch e.Code { // retry on timeout or internal server error - case 408, 500: + case http.StatusRequestTimeout, http.StatusInternalServerError: return true, nil default: return false, nil diff --git a/network/transport/http/http.go b/network/transport/http/http.go index ec7b520c..1686ead3 100644 --- a/network/transport/http/http.go +++ b/network/transport/http/http.go @@ -346,7 +346,7 @@ func (h *httpTransportSocket) error(m *transport.Message) error { Header: make(http.Header), Body: ioutil.NopCloser(bytes.NewReader(m.Body)), Status: "500 Internal Server Error", - StatusCode: 500, + StatusCode: http.StatusInternalServerError, Proto: "HTTP/1.1", ProtoMajor: 1, ProtoMinor: 1, diff --git a/util/http/http.go b/util/http/http.go index 9b80c899..1cf0cfbc 100644 --- a/util/http/http.go +++ b/util/http/http.go @@ -30,7 +30,7 @@ func WriteBadRequestError(w http.ResponseWriter, err error) { WriteInternalServerError(w, err) return } - Write(w, "application/json", 400, string(rawBody)) + Write(w, "application/json", http.StatusBadRequest, string(rawBody)) } // WriteInternalServerError sets a 500 status code