File tree 1 file changed +20
-7
lines changed 1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -18,20 +18,33 @@ fn main() {
18
18
match uber:: products:: get ( query_params) {
19
19
Ok ( result) => match result. body ( ) {
20
20
OkBody :: Status200 ( body) => {
21
- let list = body. products . unwrap_or ( vec ! [ ] ) ;
22
- println ! ( "First product: {:?}" , list[ 0 ] ) ;
21
+ let list = body. products
22
+ . unwrap_or ( vec ! [ ] ) ;
23
+
24
+ if list. len ( ) > 0 {
25
+ let first = & list[ 0 ] ;
26
+ let default = String :: from ( "Unknown" ) ;
27
+ let first_id = first. product_id
28
+ . as_ref ( )
29
+ . unwrap_or ( & default) ;
30
+
31
+ println ! ( "First product: {}" , first_id) ;
32
+ } else {
33
+ println ! ( "No products!" ) ;
34
+ }
23
35
} ,
24
36
OkBody :: UnspecifiedCode ( body) => println ! (
25
37
"Grr.. the server returned something not in its schema: {}" ,
26
38
body
27
39
)
28
40
} ,
29
41
Err ( result) => match result. body ( ) {
30
- ErrBody :: UnspecifiedCode ( body) => println ! (
31
- "Error message: {:?}" ,
32
- body. message
33
- . unwrap_or( String :: from( "[No message]" ) )
34
- ) ,
42
+ ErrBody :: UnspecifiedCode ( body) => {
43
+ let message = body. message
44
+ . unwrap_or ( String :: from ( "[None given]" ) ) ;
45
+
46
+ println ! ( "Error message: {}" , message) ;
47
+ } ,
35
48
ErrBody :: NetworkFailure ( ) => println ! ( "Request failed!" ) ,
36
49
} ,
37
50
}
You can’t perform that action at this time.
0 commit comments