@@ -7,26 +7,26 @@ use primitives::event_submission::{RateLimit, Rule};
7
7
use primitives:: sentry:: Event ;
8
8
use primitives:: Channel ;
9
9
use std:: cmp:: PartialEq ;
10
- use std:: error:: Error ;
10
+ use std:: error;
11
11
use std:: fmt;
12
12
13
13
#[ derive( Debug , PartialEq , Eq ) ]
14
- pub enum AccessError {
14
+ pub enum Error {
15
15
OnlyCreatorCanCloseChannel ,
16
16
ChannelIsExpired ,
17
17
ChannelIsInWithdrawPeriod ,
18
18
RulesError ( String ) ,
19
19
}
20
20
21
- impl Error for AccessError { }
21
+ impl error :: Error for Error { }
22
22
23
- impl fmt:: Display for AccessError {
23
+ impl fmt:: Display for Error {
24
24
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
25
25
match self {
26
- AccessError :: OnlyCreatorCanCloseChannel => write ! ( f, "only creator can create channel" ) ,
27
- AccessError :: ChannelIsExpired => write ! ( f, "channel has expired" ) ,
28
- AccessError :: ChannelIsInWithdrawPeriod => write ! ( f, "channel is in withdraw period" ) ,
29
- AccessError :: RulesError ( error) => write ! ( f, "{}" , error) ,
26
+ Error :: OnlyCreatorCanCloseChannel => write ! ( f, "only creator can create channel" ) ,
27
+ Error :: ChannelIsExpired => write ! ( f, "channel has expired" ) ,
28
+ Error :: ChannelIsInWithdrawPeriod => write ! ( f, "channel is in withdraw period" ) ,
29
+ Error :: RulesError ( error) => write ! ( f, "{}" , error) ,
30
30
}
31
31
}
32
32
}
@@ -38,7 +38,7 @@ pub async fn check_access(
38
38
rate_limit : & RateLimit ,
39
39
channel : & Channel ,
40
40
events : & [ Event ] ,
41
- ) -> Result < ( ) , AccessError > {
41
+ ) -> Result < ( ) , Error > {
42
42
let is_close_event = |e : & Event | match e {
43
43
Event :: Close => true ,
44
44
_ => false ,
@@ -47,7 +47,7 @@ pub async fn check_access(
47
47
let is_in_withdraw_period = current_time > channel. spec . withdraw_period_start ;
48
48
49
49
if current_time > channel. valid_until {
50
- return Err ( AccessError :: ChannelIsExpired ) ;
50
+ return Err ( Error :: ChannelIsExpired ) ;
51
51
}
52
52
53
53
// We're only sending a CLOSE
@@ -60,11 +60,11 @@ pub async fn check_access(
60
60
61
61
// Only the creator can send a CLOSE
62
62
if session. uid != channel. creator && events. iter ( ) . any ( is_close_event) {
63
- return Err ( AccessError :: OnlyCreatorCanCloseChannel ) ;
63
+ return Err ( Error :: OnlyCreatorCanCloseChannel ) ;
64
64
}
65
65
66
66
if is_in_withdraw_period {
67
- return Err ( AccessError :: ChannelIsInWithdrawPeriod ) ;
67
+ return Err ( Error :: ChannelIsInWithdrawPeriod ) ;
68
68
}
69
69
70
70
let default_rules = [
@@ -106,7 +106,7 @@ pub async fn check_access(
106
106
) ;
107
107
108
108
if let Err ( rule_error) = apply_all_rules. await {
109
- Err ( AccessError :: RulesError ( rule_error) )
109
+ Err ( Error :: RulesError ( rule_error) )
110
110
} else {
111
111
Ok ( ( ) )
112
112
}
@@ -239,7 +239,7 @@ mod test {
239
239
let err_response =
240
240
check_access ( & redis, & session, & config. ip_rate_limit , & channel, & events) . await ;
241
241
assert_eq ! (
242
- Err ( AccessError :: RulesError (
242
+ Err ( Error :: RulesError (
243
243
"rateLimit: too many requests" . to_string( )
244
244
) ) ,
245
245
err_response
@@ -275,7 +275,7 @@ mod test {
275
275
. await ;
276
276
277
277
assert_eq ! (
278
- Err ( AccessError :: RulesError (
278
+ Err ( Error :: RulesError (
279
279
"rateLimit: only allows 1 event" . to_string( )
280
280
) ) ,
281
281
err_response
0 commit comments