Skip to content

Commit

Permalink
cherry pick tikv#2722 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
JmPotato authored and ti-srebot committed Sep 7, 2020
1 parent 6830f5b commit 00e632d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/apiutil/serverapi/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,29 @@ func (p *customReverseProxies) ServeHTTP(w http.ResponseWriter, r *http.Request)

resp, err := p.client.Do(r)
if err != nil {
<<<<<<< HEAD
log.Error("request failed", errs.ZapError(errs.ErrSendRequest, err))
=======
log.Error("request failed", errs.ZapError(errs.ErrRequestHTTP, err))
>>>>>>> a6cb51b... apiutil: refine the log errs in apiutil (#2722)
continue
}

b, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
<<<<<<< HEAD
log.Error("read failed", errs.ZapError(errs.ErrIORead, err))
=======
log.Error("read failed", errs.ZapError(errs.ErrReadHTTPBody, err))
>>>>>>> a6cb51b... apiutil: refine the log errs in apiutil (#2722)
continue
}

copyHeader(w.Header(), resp.Header)
w.WriteHeader(resp.StatusCode)
if _, err := w.Write(b); err != nil {
log.Error("write failed", zap.Error(err))
log.Error("write failed", errs.ZapError(errs.ErrWriteHTTPBody, err))
continue
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,10 @@ var (
var (
ErrInitLogger = errors.Normalize("init logger error", errors.RFCCodeText("PD:log:ErrInitLogger"))
)

// apiutil errors
var (
ErrRequestHTTP = errors.Normalize("send HTTP request failed", errors.RFCCodeText("PD:apiutil:ErrRequestHTTP"))
ErrReadHTTPBody = errors.Normalize("read HTTP body failed", errors.RFCCodeText("PD:apiutil:ErrReadHTTPBody"))
ErrWriteHTTPBody = errors.Normalize("write HTTP body failed", errors.RFCCodeText("PD:apiutil:ErrWriteHTTPBody"))
)

0 comments on commit 00e632d

Please sign in to comment.