Improve error handling, ensure robust defaults, and eliminate unsafe unwraps/expectations across modules.
This commit is contained in:
@@ -34,7 +34,8 @@ where
|
||||
)
|
||||
.await?;
|
||||
|
||||
conn.write_all(serde_json::to_string(&backup)?.as_bytes()).await?;
|
||||
conn.write_all(serde_json::to_string(&backup)?.as_bytes())
|
||||
.await?;
|
||||
Ok(Some(200))
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ pub(crate) async fn backup_config<T, const N: usize>(
|
||||
where
|
||||
T: Read + Write,
|
||||
{
|
||||
let input = read_up_to_bytes_from_request(conn, Option::None).await?;
|
||||
let input = read_up_to_bytes_from_request(conn, Some(4096)).await?;
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
let config_to_backup = serde_json::from_slice(&input)?;
|
||||
board.board_hal.backup_config(&config_to_backup).await?;
|
||||
@@ -70,10 +71,9 @@ where
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
let info = board.board_hal.backup_info().await;
|
||||
|
||||
|
||||
let json = match info {
|
||||
Ok(h) => {
|
||||
let timestamp = DateTime::from_timestamp_millis(h.timestamp).unwrap();
|
||||
let timestamp = DateTime::from_timestamp_millis(h.timestamp).unwrap_or_default();
|
||||
let wbh = WebBackupHeader {
|
||||
timestamp: timestamp.to_rfc3339(),
|
||||
size: h.size,
|
||||
|
||||
Reference in New Issue
Block a user