diff --git a/pkg/api/middleware/validate.go b/pkg/api/middleware/validate.go index 257873d..0860de0 100644 --- a/pkg/api/middleware/validate.go +++ b/pkg/api/middleware/validate.go @@ -47,17 +47,17 @@ func ValidateRequest(service, permission string, conn *grpc.ClientConn) gin.Hand return } + // Set the remaining rate limits in the response headers + ctx.Header(HeaderRateLimitBurst, strconv.FormatUint(resp.RemainingBurst, 10)) + ctx.Header(HeaderRateLimitDaily, strconv.FormatUint(resp.RemainingDaily, 10)) + ctx.Header(HeaderRateLimitMonthly, strconv.FormatUint(resp.RemainingMonthly, 10)) + if !resp.Valid { ctx.JSON(int(resp.StatusCode), gin.H{"error": resp.ErrorMessage}) ctx.Abort() return } - // Set the remaining rate limits in the response headers - ctx.Header(HeaderRateLimitBurst, strconv.FormatUint(resp.RemainingBurst, 10)) - ctx.Header(HeaderRateLimitDaily, strconv.FormatUint(resp.RemainingDaily, 10)) - ctx.Header(HeaderRateLimitMonthly, strconv.FormatUint(resp.RemainingMonthly, 10)) - ctx.Next() } }