Skip to content

Commit

Permalink
ok_or
Browse files Browse the repository at this point in the history
  • Loading branch information
yjhmelody committed Jun 25, 2024
1 parent 7cc9fb2 commit 3bfc662
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{bail, Context};
use anyhow::{anyhow, bail, Context};
use regex::{Captures, Regex};
use std::env;
use std::fs;
Expand Down Expand Up @@ -215,7 +215,7 @@ pub async fn validate(config: &Config) -> Result<(), anyhow::Error> {

if let Some(rate_limit) = config.extensions.rate_limit.as_ref() {
if let Some(ref rule) = rate_limit.ip {
let burst = NonZeroU32::new(rule.burst).unwrap();
let burst = NonZeroU32::new(rule.burst).ok_or(anyhow!("burst could not be zero"))?;
let period = Duration::from_secs(rule.period_secs);
let quota = build_quota(burst, period);
let limiter = RateLimiter::direct(quota);
Expand All @@ -230,7 +230,7 @@ pub async fn validate(config: &Config) -> Result<(), anyhow::Error> {
}

if let Some(ref rule) = rate_limit.connection {
let burst = NonZeroU32::new(rule.burst).unwrap();
let burst = NonZeroU32::new(rule.burst).ok_or(anyhow!("burst could not be zero"))?;
let period = Duration::from_secs(rule.period_secs);
let quota = build_quota(burst, period);
let limiter = RateLimiter::direct(quota);
Expand Down

0 comments on commit 3bfc662

Please sign in to comment.