scores: improve error handling for invalid monitor parameters
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -98,7 +98,7 @@ func (srv *Server) getHistoryParameters(ctx context.Context, c echo.Context) (hi
|
|||||||
monitorParam = monitorParam + ".%"
|
monitorParam = monitorParam + ".%"
|
||||||
monitor, err := q.GetMonitorByName(ctx, sql.NullString{Valid: true, String: monitorParam})
|
monitor, err := q.GetMonitorByName(ctx, sql.NullString{Valid: true, String: monitorParam})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("could not find monitor", "name", monitorParam, "err", err)
|
log.WarnContext(ctx, "could not find monitor", "name", monitorParam, "err", err)
|
||||||
return p, echo.NewHTTPError(http.StatusNotFound, "monitor not found")
|
return p, echo.NewHTTPError(http.StatusNotFound, "monitor not found")
|
||||||
}
|
}
|
||||||
monitorID = monitor.ID
|
monitorID = monitor.ID
|
||||||
@@ -152,14 +152,20 @@ func (srv *Server) history(c echo.Context) error {
|
|||||||
|
|
||||||
p, err := srv.getHistoryParameters(ctx, c)
|
p, err := srv.getHistoryParameters(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("get history parameters", "err", err)
|
if he, ok := err.(*echo.HTTPError); ok {
|
||||||
|
return he
|
||||||
|
}
|
||||||
|
log.ErrorContext(ctx, "get history parameters", "err", err)
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "internal error")
|
return echo.NewHTTPError(http.StatusInternalServerError, "internal error")
|
||||||
}
|
}
|
||||||
|
|
||||||
server, err := srv.FindServer(ctx, c.Param("server"))
|
server, err := srv.FindServer(ctx, c.Param("server"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("find server", "err", err)
|
log.ErrorContext(ctx, "find server", "err", err)
|
||||||
|
if he, ok := err.(*echo.HTTPError); ok {
|
||||||
|
return he
|
||||||
|
}
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "internal error")
|
return echo.NewHTTPError(http.StatusInternalServerError, "internal error")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user