MSP-7466 add requestId
This commit is contained in:
1 parent
8b672bdd30
commit
dc867802d4
1 file changed
+6
-2
@@ -5,10 +5,12 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-gate-service/domain"
|
||||
"isp-gate-service/httperrors"
|
||||
"isp-gate-service/request"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/requestid"
|
||||
)
|
||||
|
||||
type Throttler interface {
|
||||
@@ -28,10 +30,12 @@ func Throttling(throttler Throttler) Middleware {
|
||||
return errors.WithMessage(err, "throttling: allow rate limit")
|
||||
}
|
||||
if !result.Allow {
|
||||
requestId := requestid.FromContext(ctx.Context())
|
||||
return httperrors.New(
|
||||
http.StatusTooManyRequests,
|
||||
fmt.Sprintf("rate limit has been reached, try after %dms", result.RetryAfter.Milliseconds()),
|
||||
errors.Errorf("throttling: rate limit has been reached for application '%d'", authData.ApplicationId),
|
||||
errors.Errorf("throttling: rate limit has been reached for application '%d', requestId '%s'",
|
||||
authData.ApplicationId, requestId),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user