@@ -4,7 +4,7 @@ use esp_idf_svc::{
44 client:: { Configuration , EspHttpConnection } ,
55 Method ,
66 } ,
7- io:: EspIOError ,
7+ io:: EspIOError , sys :: EspError ,
88} ;
99use mfrc522:: Uid ;
1010
@@ -15,7 +15,13 @@ pub enum CardError {
1515}
1616
1717impl From < EspIOError > for CardError {
18- fn from ( value : EspIOError ) -> Self {
18+ fn from ( _: EspIOError ) -> Self {
19+ CardError :: ConnectionError
20+ }
21+ }
22+
23+ impl From < EspError > for CardError {
24+ fn from ( _: EspError ) -> Self {
1925 CardError :: ConnectionError
2026 }
2127}
@@ -26,8 +32,7 @@ pub fn hannes_is_the_best_in_sending_requests(uid: Uid, auth_key: &str) -> Resul
2632 use_global_ca_store : true ,
2733 crt_bundle_attach : Some ( esp_idf_svc:: sys:: esp_crt_bundle_attach) ,
2834 ..Default :: default ( )
29- } )
30- . unwrap ( ) ,
35+ } ) ?,
3136 ) ;
3237 let mut request = client. request (
3338 Method :: Post ,
@@ -37,9 +42,11 @@ pub fn hannes_is_the_best_in_sending_requests(uid: Uid, auth_key: &str) -> Resul
3742 let _ = request. write ( format ! ( "{};{}" , hex:: encode( uid. as_bytes( ) ) , auth_key) . as_bytes ( ) ) ;
3843 let response = request. submit ( ) ?;
3944 log:: info!( "response code: {}" , response. status( ) ) ;
40- if response. status ( ) == 200 {
45+ if 200 <= response. status ( ) && response . status ( ) < 300 {
4146 Ok ( ( ) )
42- } else {
47+ } else if response . status ( ) == 404 {
4348 Err ( CardError :: NotFoundError )
49+ } else {
50+ Err ( CardError :: ServerError )
4451 }
4552}
0 commit comments