File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ impl LimitedAction {
27
27
}
28
28
}
29
29
30
+ pub fn error_message ( & self ) -> & ' static str {
31
+ match self {
32
+ LimitedAction :: PublishNew => {
33
+ "You have published too many new crates in a short period of time."
34
+ }
35
+ }
36
+ }
37
+
30
38
/// Key used to identify this action in environment variables. See `src/config.rs`.
31
39
pub fn env_var_key ( & self ) -> & ' static str {
32
40
match self {
@@ -62,6 +70,7 @@ impl RateLimiter {
62
70
Ok ( ( ) )
63
71
} else {
64
72
Err ( Box :: new ( TooManyRequests {
73
+ action,
65
74
retry_after : bucket. last_refill
66
75
+ chrono:: Duration :: from_std ( self . config [ & action] . rate ) . unwrap ( ) ,
67
76
} ) )
Original file line number Diff line number Diff line change 1
1
use std:: fmt;
2
2
3
3
use super :: { AppError , InternalAppErrorStatic } ;
4
+ use crate :: rate_limiter:: LimitedAction ;
4
5
use crate :: util:: { json_response, AppResponse } ;
5
6
6
7
use chrono:: NaiveDateTime ;
@@ -90,6 +91,7 @@ pub(super) struct BadRequest(pub(super) String);
90
91
pub ( super ) struct ServerError ( pub ( super ) String ) ;
91
92
#[ derive( Debug ) ]
92
93
pub ( crate ) struct TooManyRequests {
94
+ pub action : LimitedAction ,
93
95
pub retry_after : NaiveDateTime ,
94
96
}
95
97
@@ -137,9 +139,9 @@ impl AppError for TooManyRequests {
137
139
let retry_after = self . retry_after . format ( HTTP_DATE_FORMAT ) ;
138
140
139
141
let detail = format ! (
140
- "You have published too many crates in a \
141
- short period of time. Please try again after {} or email \
142
+ "{} Please try again after {} or email \
142
143
[email protected] to have your limit increased.",
144
+ self . action. error_message( ) ,
143
145
retry_after
144
146
) ;
145
147
let mut response = json_error ( & detail, StatusCode :: TOO_MANY_REQUESTS ) ;
You can’t perform that action at this time.
0 commit comments