mirror of https://github.com/status-im/consul.git
add comment codes
This commit is contained in:
parent
00dd9d6b78
commit
e2065e10c0
|
@ -297,7 +297,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
||||||
formVals, err := url.ParseQuery(req.URL.RawQuery)
|
formVals, err := url.ParseQuery(req.URL.RawQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Printf("[ERR] http: Failed to decode query: %s from=%s", err, req.RemoteAddr)
|
s.logger.Printf("[ERR] http: Failed to decode query: %s from=%s", err, req.RemoteAddr)
|
||||||
resp.WriteHeader(http.StatusInternalServerError)
|
resp.WriteHeader(http.StatusInternalServerError) // 500
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logURL := req.URL.String()
|
logURL := req.URL.String()
|
||||||
|
@ -331,10 +331,10 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
||||||
HAS_ERR:
|
HAS_ERR:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Printf("[ERR] http: Request %s %v, error: %v from=%s", req.Method, logURL, err, req.RemoteAddr)
|
s.logger.Printf("[ERR] http: Request %s %v, error: %v from=%s", req.Method, logURL, err, req.RemoteAddr)
|
||||||
code := http.StatusInternalServerError
|
code := http.StatusInternalServerError // 500
|
||||||
errMsg := err.Error()
|
errMsg := err.Error()
|
||||||
if strings.Contains(errMsg, "Permission denied") || strings.Contains(errMsg, "ACL not found") {
|
if strings.Contains(errMsg, "Permission denied") || strings.Contains(errMsg, "ACL not found") {
|
||||||
code = http.StatusForbidden
|
code = http.StatusForbidden // 403
|
||||||
}
|
}
|
||||||
resp.WriteHeader(code)
|
resp.WriteHeader(code)
|
||||||
resp.Write([]byte(err.Error()))
|
resp.Write([]byte(err.Error()))
|
||||||
|
@ -367,7 +367,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
||||||
func (s *HTTPServer) Index(resp http.ResponseWriter, req *http.Request) {
|
func (s *HTTPServer) Index(resp http.ResponseWriter, req *http.Request) {
|
||||||
// Check if this is a non-index path
|
// Check if this is a non-index path
|
||||||
if req.URL.Path != "/" {
|
if req.URL.Path != "/" {
|
||||||
resp.WriteHeader(http.StatusNotFound)
|
resp.WriteHeader(http.StatusNotFound) // 404
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ func (s *HTTPServer) Index(resp http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect to the UI endpoint
|
// Redirect to the UI endpoint
|
||||||
http.Redirect(resp, req, "/ui/", http.StatusMovedPermanently)
|
http.Redirect(resp, req, "/ui/", http.StatusMovedPermanently) // 301
|
||||||
}
|
}
|
||||||
|
|
||||||
// decodeBody is used to decode a JSON request body
|
// decodeBody is used to decode a JSON request body
|
||||||
|
@ -439,7 +439,7 @@ func parseWait(resp http.ResponseWriter, req *http.Request, b *structs.QueryOpti
|
||||||
if wait := query.Get("wait"); wait != "" {
|
if wait := query.Get("wait"); wait != "" {
|
||||||
dur, err := time.ParseDuration(wait)
|
dur, err := time.ParseDuration(wait)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.WriteHeader(http.StatusBadRequest)
|
resp.WriteHeader(http.StatusBadRequest) // 400
|
||||||
resp.Write([]byte("Invalid wait time"))
|
resp.Write([]byte("Invalid wait time"))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -448,7 +448,7 @@ func parseWait(resp http.ResponseWriter, req *http.Request, b *structs.QueryOpti
|
||||||
if idx := query.Get("index"); idx != "" {
|
if idx := query.Get("index"); idx != "" {
|
||||||
index, err := strconv.ParseUint(idx, 10, 64)
|
index, err := strconv.ParseUint(idx, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.WriteHeader(http.StatusBadRequest)
|
resp.WriteHeader(http.StatusBadRequest) // 400
|
||||||
resp.Write([]byte("Invalid index"))
|
resp.Write([]byte("Invalid index"))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ func parseConsistency(resp http.ResponseWriter, req *http.Request, b *structs.Qu
|
||||||
b.RequireConsistent = true
|
b.RequireConsistent = true
|
||||||
}
|
}
|
||||||
if b.AllowStale && b.RequireConsistent {
|
if b.AllowStale && b.RequireConsistent {
|
||||||
resp.WriteHeader(http.StatusBadRequest)
|
resp.WriteHeader(http.StatusBadRequest) // 400
|
||||||
resp.Write([]byte("Cannot specify ?stale with ?consistent, conflicting semantics."))
|
resp.Write([]byte("Cannot specify ?stale with ?consistent, conflicting semantics."))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue