Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions crates/services/src/agent/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,15 +1182,22 @@ impl AgentService for AgentServiceImpl {
.await
.map_err(|e| anyhow!("Failed to call Agent API delete: {}", e))?;

if !response.status().is_success() {
return Err(anyhow!(
"Agent API delete failed with status {}: instance_id={}",
response.status(),
instance_id
));
let status = response.status();
if !status.is_success() {
if status == reqwest::StatusCode::NOT_FOUND {
tracing::warn!(
"Instance not found on instance manager (already removed?), proceeding with DB soft-delete: instance_id={}",
instance_id
);
} else {
return Err(anyhow!(
"Agent API delete failed with status {}: instance_id={}",
status,
instance_id
));
}
}

Comment on lines +1187 to 1200

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and to make it easier to handle other status codes in the future, you could use a match statement here to handle the non-success status codes.

Suggested change
if status == reqwest::StatusCode::NOT_FOUND {
tracing::warn!(
"Instance not found on instance manager (already removed?), proceeding with DB soft-delete: instance_id={}",
instance_id
);
} else {
return Err(anyhow!(
"Agent API delete failed with status {}: instance_id={}",
status,
instance_id
));
}
}
if !status.is_success() {
match status {
reqwest::StatusCode::NOT_FOUND => {
tracing::warn!(
"Instance not found on instance manager (already removed?), proceeding with DB soft-delete: instance_id={}",
instance_id
);
}
_ => {
return Err(anyhow!(
"Agent API delete failed with status {}: instance_id={}",
status,
instance_id
));
}
}
}

// Only delete from database if remote deletion was successful
self.repository.delete_instance(instance_id).await?;

tracing::info!(
Expand Down