From 2017f3a809beeece6cc9cbceeba6bea032a0ecd6 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 11 Jun 2020 10:10:18 +0700 Subject: http: log endpoint call only if its not instance of errors.E --- lib/http/endpoint.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/http') diff --git a/lib/http/endpoint.go b/lib/http/endpoint.go index 4b084233..a5391cb6 100644 --- a/lib/http/endpoint.go +++ b/lib/http/endpoint.go @@ -113,7 +113,7 @@ func (ep *Endpoint) call( for _, eval := range evaluators { e = eval(req, reqBody) if e != nil { - ep.error(res, e) + ep.error(res, req, e) return } } @@ -121,17 +121,14 @@ func (ep *Endpoint) call( if ep.Eval != nil { e = ep.Eval(req, reqBody) if e != nil { - ep.error(res, e) + ep.error(res, req, e) return } } rspb, e := ep.Call(res, req, reqBody) if e != nil { - log.Printf("endpoint.call: %d %s %s %s\n", - http.StatusInternalServerError, - req.Method, req.URL.Path, e) - ep.error(res, e) + ep.error(res, req, e) return } @@ -159,13 +156,17 @@ func (ep *Endpoint) call( } } -func (ep *Endpoint) error(res http.ResponseWriter, err error) { +func (ep *Endpoint) error(res http.ResponseWriter, req *http.Request, err error) { errInternal := &errors.E{} if stderrors.As(err, &errInternal) { if errInternal.Code <= 0 || errInternal.Code >= 512 { errInternal.Code = http.StatusInternalServerError } } else { + log.Printf("endpoint.call: %d %s %s %s\n", + http.StatusInternalServerError, + req.Method, req.URL.Path, err) + errInternal = errors.Internal(err) } -- cgit v1.3