Private
Public Access
1
0

Fix 500 errors when requesting with an invalid or unknown monitor parameter
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2024-07-21 04:31:42 -07:00
parent 79eea1d0f8
commit 397dd13c38
4 changed files with 23 additions and 106 deletions

View File

@@ -98,8 +98,11 @@ func (srv *Server) getHistoryParameters(ctx context.Context, c echo.Context) (hi
monitorParam = monitorParam + ".%"
monitor, err := q.GetMonitorByName(ctx, sql.NullString{Valid: true, String: monitorParam})
if err != nil {
if err == sql.ErrNoRows {
return p, echo.NewHTTPError(http.StatusNotFound, "monitor not found").WithInternal(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 (sql)")
}
monitorID = monitor.ID

View File

@@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"log/slog"
"net/http"
"os"
@@ -102,6 +103,8 @@ func (srv *Server) Run() error {
e := echo.New()
srv.tpShutdown = append(srv.tpShutdown, e.Shutdown)
e.Debug = false
trustOptions := []echo.TrustOption{
echo.TrustLoopback(true),
echo.TrustLinkLocal(false),
@@ -128,9 +131,13 @@ func (srv *Server) Run() error {
Registerer: srv.metrics.Registry(),
}))
e.Use(otelecho.Middleware("data-api"))
e.Use(slogecho.NewWithConfig(log,
slogecho.Config{
WithTraceID: false, // done by logger already
WithTraceID: false, // done by logger already
DefaultLevel: slog.LevelInfo,
ClientErrorLevel: slog.LevelWarn,
ServerErrorLevel: slog.LevelError,
// WithRequestHeader: true,
},
))