feat(backend): moved log to prevent error code loss
This commit is contained in:
parent
45c956c489
commit
a453256f23
1 changed files with 2 additions and 2 deletions
|
|
@ -24,13 +24,13 @@ func (e *Router) ResponseOK(ctx context.Context, w http.ResponseWriter, requestS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Router) ResponseWithJSON(ctx context.Context, w http.ResponseWriter, res interface{}, requestStart time.Time, url string, bodySize int) {
|
func (e *Router) ResponseWithJSON(ctx context.Context, w http.ResponseWriter, res interface{}, requestStart time.Time, url string, bodySize int) {
|
||||||
|
e.log.Info(ctx, "response ok")
|
||||||
body, err := json.Marshal(res)
|
body, err := json.Marshal(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.log.Error(ctx, "can't marshal response: %s", err)
|
e.log.Error(ctx, "can't marshal response: %s", err)
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(body)
|
w.Write(body)
|
||||||
e.log.Info(ctx, "response ok")
|
|
||||||
recordMetrics(requestStart, url, http.StatusOK, bodySize)
|
recordMetrics(requestStart, url, http.StatusOK, bodySize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,12 +39,12 @@ type response struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Router) ResponseWithError(ctx context.Context, w http.ResponseWriter, code int, err error, requestStart time.Time, url string, bodySize int) {
|
func (e *Router) ResponseWithError(ctx context.Context, w http.ResponseWriter, code int, err error, requestStart time.Time, url string, bodySize int) {
|
||||||
|
e.log.Error(ctx, "response error, code: %d, error: %s", code, err)
|
||||||
body, err := json.Marshal(&response{err.Error()})
|
body, err := json.Marshal(&response{err.Error()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.log.Error(ctx, "can't marshal response: %s", err)
|
e.log.Error(ctx, "can't marshal response: %s", err)
|
||||||
}
|
}
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
w.Write(body)
|
w.Write(body)
|
||||||
e.log.Error(ctx, "response error, code: %d, error: %s", code, err)
|
|
||||||
recordMetrics(requestStart, url, code, bodySize)
|
recordMetrics(requestStart, url, code, bodySize)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue