Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Binding cannot be cast to the type RateLimiter from Ratelimit #700

Open
1 task done
maxdeviant opened this issue Jan 29, 2025 · 0 comments
Open
1 task done

Comments

@maxdeviant
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

What version of workers-rs are you using?

0.5.0

What version of wrangler are you using?

3.106.0

Describe the bug

When trying to retrieve a RateLimiter with Env::get_binding the following error occurs:

Binding cannot be cast to the type RateLimiter from Ratelimit

Steps To Reproduce

I have the following in my wrangler.toml:

[[unsafe.bindings]]
name = "MY_RATE_LIMITER"
type = "ratelimit"
namespace_id = "1001"
simple = { limit = 10, period = 60}

And the rate limiter is being retrieved like so:

// ...

let rate_limiter = cx
    .env
    .get_binding::<RateLimiter>("MY_RATE_LIMITER")?;

let rate_limit_outcome = rate_limiter
    .limit(format!("user_id:{}", claims.user_id))
    .await?;
if !rate_limit_outcome.success {
    return Response::error(
        "Rate limit exceeded.",
        StatusCode::TOO_MANY_REQUESTS.as_u16(),
    );
}

Related GitHub Discussion: #692

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant