Merge branch 'master' of ssh://github.com/asim/go-micro

This commit is contained in:
Asim Aslam
2020-10-18 08:10:56 +01:00
6 changed files with 12 additions and 11 deletions

View File

@@ -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
}

View File

@@ -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))
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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,

View File

@@ -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