Merge branch 'master' of ssh://github.com/asim/go-micro
This commit is contained in:
@@ -28,7 +28,7 @@ type httpHandler struct {
|
|||||||
func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
service, err := h.getService(r)
|
service, err := h.getService(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
rp, err := url.Parse(service)
|
rp, err := url.Parse(service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -428,11 +428,11 @@ func writeError(w http.ResponseWriter, r *http.Request, err error) {
|
|||||||
switch ce.Code {
|
switch ce.Code {
|
||||||
case 0:
|
case 0:
|
||||||
// assuming it's totally screwed
|
// assuming it's totally screwed
|
||||||
ce.Code = 500
|
ce.Code = http.StatusInternalServerError
|
||||||
ce.Id = "go.micro.api"
|
ce.Id = "go.micro.api"
|
||||||
ce.Status = http.StatusText(500)
|
ce.Status = http.StatusText(http.StatusInternalServerError)
|
||||||
ce.Detail = "error during request: " + ce.Detail
|
ce.Detail = "error during request: " + ce.Detail
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
default:
|
default:
|
||||||
w.WriteHeader(int(ce.Code))
|
w.WriteHeader(int(ce.Code))
|
||||||
}
|
}
|
||||||
|
@@ -283,7 +283,7 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
b, err := ioutil.ReadAll(req.Body)
|
b, err := ioutil.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err)
|
errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err)
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(errr.Error()))
|
w.Write([]byte(errr.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -291,7 +291,7 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
var msg *broker.Message
|
var msg *broker.Message
|
||||||
if err = h.opts.Codec.Unmarshal(b, &msg); err != nil {
|
if err = h.opts.Codec.Unmarshal(b, &msg); err != nil {
|
||||||
errr := merr.InternalServerError("go.micro.broker", "Error parsing request body: %v", err)
|
errr := merr.InternalServerError("go.micro.broker", "Error parsing request body: %v", err)
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(errr.Error()))
|
w.Write([]byte(errr.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -300,7 +300,7 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
if len(topic) == 0 {
|
if len(topic) == 0 {
|
||||||
errr := merr.InternalServerError("go.micro.broker", "Topic not found")
|
errr := merr.InternalServerError("go.micro.broker", "Topic not found")
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(errr.Error()))
|
w.Write([]byte(errr.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/micro/go-micro/v3/errors"
|
"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 {
|
switch e.Code {
|
||||||
// retry on timeout or internal server error
|
// retry on timeout or internal server error
|
||||||
case 408, 500:
|
case http.StatusRequestTimeout, http.StatusInternalServerError:
|
||||||
return true, nil
|
return true, nil
|
||||||
default:
|
default:
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@@ -346,7 +346,7 @@ func (h *httpTransportSocket) error(m *transport.Message) error {
|
|||||||
Header: make(http.Header),
|
Header: make(http.Header),
|
||||||
Body: ioutil.NopCloser(bytes.NewReader(m.Body)),
|
Body: ioutil.NopCloser(bytes.NewReader(m.Body)),
|
||||||
Status: "500 Internal Server Error",
|
Status: "500 Internal Server Error",
|
||||||
StatusCode: 500,
|
StatusCode: http.StatusInternalServerError,
|
||||||
Proto: "HTTP/1.1",
|
Proto: "HTTP/1.1",
|
||||||
ProtoMajor: 1,
|
ProtoMajor: 1,
|
||||||
ProtoMinor: 1,
|
ProtoMinor: 1,
|
||||||
|
@@ -30,7 +30,7 @@ func WriteBadRequestError(w http.ResponseWriter, err error) {
|
|||||||
WriteInternalServerError(w, err)
|
WriteInternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Write(w, "application/json", 400, string(rawBody))
|
Write(w, "application/json", http.StatusBadRequest, string(rawBody))
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteInternalServerError sets a 500 status code
|
// WriteInternalServerError sets a 500 status code
|
||||||
|
Reference in New Issue
Block a user