stats: imp code
This commit is contained in:
parent
bb3c0c8002
commit
022c90496a
|
@ -72,13 +72,8 @@ func (s *StatsCtx) handleStats(w http.ResponseWriter, r *http.Request) {
|
|||
if !ok {
|
||||
// Don't bring the message to the lower case since it's a part of UI
|
||||
// text for the moment.
|
||||
aghhttp.ErrorAndLog(
|
||||
ctx,
|
||||
s.logger,
|
||||
r,
|
||||
w,
|
||||
http.StatusInternalServerError, "Couldn't get statistics data",
|
||||
)
|
||||
const msg = "Couldn't get statistics data"
|
||||
aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusInternalServerError, msg)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -162,28 +157,13 @@ func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
|
|||
reqData := configResp{}
|
||||
err := json.NewDecoder(r.Body).Decode(&reqData)
|
||||
if err != nil {
|
||||
aghhttp.ErrorAndLog(
|
||||
ctx,
|
||||
s.logger,
|
||||
r,
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"json decode: %s",
|
||||
err,
|
||||
)
|
||||
aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusBadRequest, "json decode: %s", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if !checkInterval(reqData.IntervalDays) {
|
||||
aghhttp.ErrorAndLog(
|
||||
ctx,
|
||||
s.logger,
|
||||
r,
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"Unsupported interval",
|
||||
)
|
||||
aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusBadRequest, "Unsupported interval")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -206,30 +186,14 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request)
|
|||
reqData := getConfigResp{}
|
||||
err := json.NewDecoder(r.Body).Decode(&reqData)
|
||||
if err != nil {
|
||||
aghhttp.ErrorAndLog(
|
||||
ctx,
|
||||
s.logger,
|
||||
r,
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"json decode: %s",
|
||||
err,
|
||||
)
|
||||
aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusBadRequest, "json decode: %s", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
engine, err := aghnet.NewIgnoreEngine(reqData.Ignored)
|
||||
if err != nil {
|
||||
aghhttp.ErrorAndLog(
|
||||
ctx,
|
||||
s.logger,
|
||||
r,
|
||||
w,
|
||||
http.StatusUnprocessableEntity,
|
||||
"ignored: %s",
|
||||
err,
|
||||
)
|
||||
aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusUnprocessableEntity, "ignored: %s", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -251,14 +215,7 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
if reqData.Enabled == aghalg.NBNull {
|
||||
aghhttp.ErrorAndLog(
|
||||
ctx,
|
||||
s.logger,
|
||||
r,
|
||||
w,
|
||||
http.StatusUnprocessableEntity,
|
||||
"enabled is null",
|
||||
)
|
||||
aghhttp.ErrorAndLog(ctx, s.logger, r, w, http.StatusUnprocessableEntity, "enabled is null")
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue