3 Commits

Author SHA1 Message Date
xuu
cd1f1d7b5f fix: remove non-errors
All checks were successful
Go Bump / bump (push) Successful in 47s
Go Test / test (push) Successful in 59s
Deploy / deploy (push) Successful in 1m42s
2023-10-07 18:33:00 -06:00
xuu
a3ee0b7900 fix: return on errors
All checks were successful
Go Bump / bump (push) Successful in 46s
Go Test / test (push) Successful in 52s
Deploy / deploy (push) Successful in 1m42s
2023-10-07 18:11:35 -06:00
xuu
114c7101d6 fix: add debug levels
All checks were successful
Go Bump / bump (push) Successful in 43s
Go Test / test (push) Successful in 49s
Deploy / deploy (push) Successful in 1m42s
2023-10-07 17:57:09 -06:00
2 changed files with 16 additions and 3 deletions

View File

@@ -179,7 +179,7 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
return nil
})
if err != nil {
span.RecordError(err)
span.AddEvent(err.Error())
w.WriteHeader(http.StatusNotFound)
return
}
@@ -204,8 +204,9 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
peerResults.SetStreamID(aggPeer(peerID))
err = s.es.Load(ctx, peerResults)
if err != nil && !errors.Is(err, ev.ErrNotFound) {
span.RecordError(fmt.Errorf("peer not found: %w", err))
span.AddEvent("peer not found")
w.WriteHeader(http.StatusNotFound)
return
}
var req *Request
@@ -221,8 +222,9 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
}
}
if req == nil {
span.RecordError(fmt.Errorf("request not found"))
span.AddEvent("request not found")
w.WriteHeader(http.StatusNoContent)
return
}
negotiator := contentnegotiation.NewNegotiator("application/json", "text/environment", "text/plain", "text/html")
@@ -451,6 +453,7 @@ func (s *service) postResult(w http.ResponseWriter, r *http.Request, reqID strin
if err != nil {
span.RecordError(fmt.Errorf("peer not found: %w", err))
w.WriteHeader(http.StatusNotFound)
return
}
if peerResults.Has(reqID) {

View File

@@ -4,10 +4,13 @@ import (
"context"
"errors"
"log"
"log/slog"
"net/http"
"os"
"os/signal"
"strconv"
"go.sour.is/pkg/env"
"go.sour.is/pkg/lg"
"go.sour.is/pkg/service"
)
@@ -27,6 +30,13 @@ func main() {
}
}
func run(ctx context.Context) error {
// TODO: make this configurable.
level := slog.LevelError
if ok, _ := strconv.ParseBool(env.Default("LOG_DEBUG", "FALSE")); ok {
level = slog.LevelDebug
}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level})))
svc := &service.Harness{}
ctx, stop := lg.Init(ctx, appName)
svc.OnStop(stop)