5
5
6
6
#[ macro_use] extern crate rocket;
7
7
8
- use rocket:: { Request , Rocket , Build } ;
8
+ use rocket:: { Rocket , Build } ;
9
9
use rocket:: local:: blocking:: Client ;
10
- use rocket:: http:: Status ;
10
+ use rocket:: http:: { Status , uri :: Origin } ;
11
11
12
- #[ catch( 404 ) ] fn not_found_0 ( ) -> & ' static str { "404-0" }
13
- #[ catch( 404 ) ] fn not_found_1 ( _: & Request < ' _ > ) -> & ' static str { "404-1" }
14
- #[ catch( 404 ) ] fn not_found_2 ( _: Status , _: & Request < ' _ > ) -> & ' static str { "404-2" }
15
- #[ catch( default ) ] fn all ( _: Status , r : & Request < ' _ > ) -> String { r. uri ( ) . to_string ( ) }
12
+ #[ catch( 404 ) ]
13
+ fn not_found_0 ( ) -> & ' static str { "404-0" }
14
+ #[ catch( 404 ) ]
15
+ fn not_found_1 ( ) -> & ' static str { "404-1" }
16
+ #[ catch( 404 , status = "<_s>" ) ]
17
+ fn not_found_2 ( _s : Status ) -> & ' static str { "404-2" }
18
+ #[ catch( default , status = "<_s>" ) ]
19
+ fn all ( _s : Status , uri : & Origin < ' _ > ) -> String { uri. to_string ( ) }
16
20
17
21
#[ test]
18
22
fn test_simple_catchers ( ) {
@@ -37,10 +41,14 @@ fn test_simple_catchers() {
37
41
}
38
42
39
43
#[ get( "/<code>" ) ] fn forward ( code : u16 ) -> Status { Status :: new ( code) }
40
- #[ catch( 400 ) ] fn forward_400 ( status : Status , _: & Request < ' _ > ) -> String { status. code . to_string ( ) }
41
- #[ catch( 404 ) ] fn forward_404 ( status : Status , _: & Request < ' _ > ) -> String { status. code . to_string ( ) }
42
- #[ catch( 444 ) ] fn forward_444 ( status : Status , _: & Request < ' _ > ) -> String { status. code . to_string ( ) }
43
- #[ catch( 500 ) ] fn forward_500 ( status : Status , _: & Request < ' _ > ) -> String { status. code . to_string ( ) }
44
+ #[ catch( 400 , status = "<status>" ) ]
45
+ fn forward_400 ( status : Status ) -> String { status. code . to_string ( ) }
46
+ #[ catch( 404 , status = "<status>" ) ]
47
+ fn forward_404 ( status : Status ) -> String { status. code . to_string ( ) }
48
+ #[ catch( 444 , status = "<status>" ) ]
49
+ fn forward_444 ( status : Status ) -> String { status. code . to_string ( ) }
50
+ #[ catch( 500 , status = "<status>" ) ]
51
+ fn forward_500 ( status : Status ) -> String { status. code . to_string ( ) }
44
52
45
53
#[ test]
46
54
fn test_status_param ( ) {
@@ -60,11 +68,11 @@ fn test_status_param() {
60
68
}
61
69
62
70
#[ catch( 404 ) ]
63
- fn bad_req_untyped ( _ : Status , _ : & Request < ' _ > ) -> & ' static str { "404" }
64
- #[ catch( 404 ) ]
65
- fn bad_req_string ( _ : & String , _ : Status , _ : & Request < ' _ > ) -> & ' static str { "404 String" }
66
- #[ catch( 404 ) ]
67
- fn bad_req_tuple ( _ : & ( ) , _ : Status , _ : & Request < ' _ > ) -> & ' static str { "404 ()" }
71
+ fn bad_req_untyped ( ) -> & ' static str { "404" }
72
+ #[ catch( 404 , error = "<_e>" ) ]
73
+ fn bad_req_string ( _e : & String ) -> & ' static str { "404 String" }
74
+ #[ catch( 404 , error = "<_e>" ) ]
75
+ fn bad_req_tuple ( _e : & ( ) ) -> & ' static str { "404 ()" }
68
76
69
77
#[ test]
70
78
fn test_typed_catchers ( ) {
0 commit comments