From a165d5b3709b12b8087bdcc4f2b18918404a58cc Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Mon, 4 Dec 2023 18:42:40 -0800 Subject: [PATCH] Check meter --- meters/meters.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meters/meters.go b/meters/meters.go index 7808f866..ec6d58b7 100644 --- a/meters/meters.go +++ b/meters/meters.go @@ -35,8 +35,11 @@ func WithMeter(apiMeter MeterProvider, meterName string, meterValue float64, dim ctx := r.Context() ctxMeter := apiMeter.NewMeter(authn.ForContext(ctx)) r = r.WithContext(context.WithValue(ctx, meterCtxKey, ctxMeter)) + if err := ctxMeter.Meter(meterName, meterValue, dims); err != nil { + http.Error(w, "429", http.StatusTooManyRequests) + return + } next.ServeHTTP(w, r) - ctxMeter.Meter(meterName, meterValue, dims) }) } }