updated hws.ThrowError to not return an error and log it to console instead

fixed errors_test

fixed tests
This commit is contained in:
2026-02-03 18:11:17 +11:00
parent 95a17597cf
commit 563908bbb4
14 changed files with 249 additions and 239 deletions

View File

@@ -18,16 +18,24 @@ func startTimer(next http.Handler) http.Handler {
)
}
type contextKey string
func (c contextKey) String() string {
return "hws context key " + string(c)
}
var requestTimerCtxKey = contextKey("request-timer")
// Set the start time of the request
func setStart(ctx context.Context, time time.Time) context.Context {
return context.WithValue(ctx, "hws context key request-timer", time)
return context.WithValue(ctx, requestTimerCtxKey, time)
}
// Get the start time of the request
func getStartTime(ctx context.Context) (time.Time, error) {
start, ok := ctx.Value("hws context key request-timer").(time.Time)
start, ok := ctx.Value(requestTimerCtxKey).(time.Time)
if !ok {
return time.Time{}, errors.New("Failed to get start time of request")
return time.Time{}, errors.New("failed to get start time of request")
}
return start, nil
}