1
1
use example_rest_api:: {
2
- controller:: { errors:: ErrorKind , Controller } ,
2
+ controller:: { errors:: Error as ControllerError , Controller } ,
3
3
expect, get_path_param, method_handlers,
4
4
utils:: response:: no_content,
5
5
} ;
@@ -30,11 +30,8 @@ async fn handler_get(req: Request) -> Result<Response<Body>, Error> {
30
30
let objectid = get_path_param ! ( & req, "objectid" ) ;
31
31
32
32
let res = expect ! ( controller. get_object( & collectionid, & objectid) . await ,
33
- Err ( err) => match err. kind( ) {
34
- ErrorKind :: CollectionNotFound => not_found( "collection not found" ) ,
35
- _ => internal_server_error( format!( "failed getting object: {err}" ) )
36
- }
37
- ) ;
33
+ Err ( ControllerError :: CollectionNotFound ) => not_found( "collection not found" ) ,
34
+ Err ( err) => internal_server_error( format!( "failed getting object: {err}" ) ) ) ;
38
35
39
36
match res {
40
37
None => not_found ( "object not found" ) ,
@@ -53,12 +50,9 @@ async fn handler_put(req: Request) -> Result<Response<Body>, Error> {
53
50
Err ( err) => bad_request( format!( "failed decoding request body: {err}" ) ) ) ;
54
51
55
52
let res = expect ! ( controller. set_object( & collectionid, & objectid, req) . await ,
56
- Err ( err) => match err. kind( ) {
57
- ErrorKind :: CollectionNotFound => not_found( "collection not found" ) ,
58
- ErrorKind :: ObjectNotFound => not_found( "object not found" ) ,
59
- _ => internal_server_error( format!( "failed getting object: {err}" ) )
60
- }
61
- ) ;
53
+ Err ( ControllerError :: CollectionNotFound ) => not_found( "collection not found" ) ,
54
+ Err ( ControllerError :: ObjectNotFound ) => not_found( "object not found" ) ,
55
+ Err ( err) => internal_server_error( format!( "failed getting object: {err}" ) ) ) ;
62
56
63
57
ok ( res)
64
58
}
@@ -71,11 +65,8 @@ async fn handler_delete(req: Request) -> Result<Response<Body>, Error> {
71
65
let objectid = get_path_param ! ( & req, "objectid" ) ;
72
66
73
67
expect ! ( controller. delete_object( & collectionid, & objectid) . await ,
74
- Err ( err) => match err. kind( ) {
75
- ErrorKind :: CollectionNotFound => not_found( "collection not found" ) ,
76
- _ => internal_server_error( format!( "failed getting object: {err}" ) )
77
- }
78
- ) ;
68
+ Err ( ControllerError :: CollectionNotFound ) => not_found( "collection not found" ) ,
69
+ Err ( err) => internal_server_error( format!( "failed getting object: {err}" ) ) ) ;
79
70
80
71
Ok ( Response :: builder ( )
81
72
. status ( StatusCode :: NO_CONTENT )
0 commit comments