diff --git a/src/config.rs b/src/config.rs index 2308c8a..5e8348f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -63,11 +63,6 @@ async fn handler( Cache, >, ) -> ! { - let resp_fail = |_| { - // TODO: make tracing work so if this code is reached you know where the error originated - error!("failed to respond"); - }; - let mut data_buffer = [0u8; 256]; loop { @@ -75,26 +70,25 @@ async fn handler( match operation { ConfigOperationMessage::SetWifiCreds(value, resp) => { - let mut buf = [0u8; 256]; - if let Err(err) = to_slice(&value, &mut buf) { - let _ = resp.send(Err(err.into())).map_err(resp_fail); - continue; + let mut f = async || { + let mut buf = [0u8; 256]; + to_slice(&value, &mut buf)?; + + storage + .store_item(&mut data_buffer, &ConfigKey::Wifi, &buf) + .await?; + + // TODO: send the change to the wifi service + // WIFI_SERVICE + // .call(|s| s.set_station_config(esp_radio::wifi::Config::Station(value.into()))) + // .await; + + Ok(()) }; - - if let Err(err) = storage - .store_item(&mut data_buffer, &ConfigKey::Wifi, &buf) - .await - { - let _ = resp.send(Err(err.into())).map_err(resp_fail); - continue; + if resp.send(f().await).is_err() { + // TODO: find a way to not hard-code symbols in a string + error!("ConfigOperationMessage::SetWifiCreds failed to respond") }; - - // TODO: send the change to the wifi service - // WIFI_SERVICE - // .call(|s| s.set_station_config(esp_radio::wifi::Config::Station(value.into()))) - // .await; - - let _ = resp.send(Ok(())).map_err(resp_fail); } } }