Remove panics
This commit is contained in:
parent
e67f476ca4
commit
d363c00347
2 changed files with 29 additions and 8 deletions
|
|
@ -20,7 +20,7 @@ pub async fn get_key(
|
|||
Path(key): Path<String>,
|
||||
) -> Result<Response, AppError> {
|
||||
let record = state.db.get(&key).await?;
|
||||
let vol = &record.volumes[0];
|
||||
let vol = record.volumes.first().ok_or(AppError::NotFound)?;
|
||||
let location = format!("{vol}/{key}");
|
||||
Ok((StatusCode::FOUND, [(axum::http::header::LOCATION, location)]).into_response())
|
||||
}
|
||||
|
|
@ -60,9 +60,16 @@ pub async fn put_key(
|
|||
|
||||
let mut failed = false;
|
||||
for handle in handles {
|
||||
if let Err(e) = handle.await.unwrap() {
|
||||
tracing::error!("{e}");
|
||||
failed = true;
|
||||
match handle.await {
|
||||
Ok(Err(e)) => {
|
||||
tracing::error!("{e}");
|
||||
failed = true;
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("volume write task failed: {e}");
|
||||
failed = true;
|
||||
}
|
||||
Ok(Ok(())) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,8 +99,10 @@ pub async fn delete_key(
|
|||
handles.push(tokio::spawn(async move { client.delete(&url).send().await }));
|
||||
}
|
||||
for handle in handles {
|
||||
if let Err(e) = handle.await.unwrap() {
|
||||
tracing::error!("DELETE from volume failed: {e}");
|
||||
match handle.await {
|
||||
Ok(Err(e)) => tracing::error!("DELETE from volume failed: {e}"),
|
||||
Err(e) => tracing::error!("volume delete task failed: {e}"),
|
||||
Ok(Ok(_)) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue