Skip to content

Commit

Permalink
feat: improve deployer 404 messages (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
oddgrd authored Apr 19, 2023
1 parent 5bdd892 commit 4ce62aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ echo "api_key = '<jwt>'" > ~/.config/shuttle/config.toml
> Note: The JWT will expire in 15 minutes, at which point you need to run the commands again.
> If you have [`jq`](https://github.com/stedolan/jq/wiki/Installation) installed you can combine
> the two above commands into the following:
> ```bash
> curl -s -H "Authorization: Bearer test-key" localhost:8008/auth/key \
> | jq -r '.token' \
> | read token; echo "api_key='$token'" > ~/.config/shuttle/config.toml
> ```
```bash
curl -s -H "Authorization: Bearer test-key" localhost:8008/auth/key \
| jq -r '.token' \
| read token; echo "api_key='$token'" > ~/.config/shuttle/config.toml
```

Finally we need to comment out the admin layer in the deployer handlers. So in `deployer/handlers/mod.rs`,
in the `make_router` function comment out this line: `.layer(AdminSecretLayer::new(admin_secret))`.
Expand Down
6 changes: 3 additions & 3 deletions deployer/src/handlers/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub enum Error {
to: String,
message: String,
},
#[error("record could not be found")]
NotFound,
#[error("{0}, try running `cargo shuttle deploy`")]
NotFound(String),
#[error("Custom error: {0}")]
Custom(#[from] anyhow::Error),
}
Expand All @@ -44,7 +44,7 @@ impl IntoResponse for Error {
error!(error = &self as &dyn std::error::Error, "request error");

let code = match self {
Error::NotFound => StatusCode::NOT_FOUND,
Error::NotFound(_) => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR,
};

Expand Down
18 changes: 9 additions & 9 deletions deployer/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async fn get_service(

Ok(Json(response))
} else {
Err(Error::NotFound)
Err(Error::NotFound("service not found".to_string()))
}
}

Expand All @@ -166,7 +166,7 @@ async fn get_service_resources(

Ok(Json(resources))
} else {
Err(Error::NotFound)
Err(Error::NotFound("service not found".to_string()))
}
}

Expand Down Expand Up @@ -229,7 +229,7 @@ async fn stop_service(
if let Some(ref deployment) = running_deployment {
deployment_manager.kill(deployment.id).await;
} else {
return Err(Error::NotFound);
return Err(Error::NotFound("no running deployment found".to_string()));
}

let response = shuttle_common::models::service::Summary {
Expand All @@ -240,7 +240,7 @@ async fn stop_service(

Ok(Json(response))
} else {
Err(Error::NotFound)
Err(Error::NotFound("service not found".to_string()))
}
}

Expand All @@ -259,7 +259,7 @@ async fn get_deployments(

Ok(Json(deployments))
} else {
Err(Error::NotFound)
Err(Error::NotFound("service not found".to_string()))
}
}

Expand All @@ -271,7 +271,7 @@ async fn get_deployment(
if let Some(deployment) = persistence.get_deployment(&deployment_id).await? {
Ok(Json(deployment.into()))
} else {
Err(Error::NotFound)
Err(Error::NotFound("deployment not found".to_string()))
}
}

Expand All @@ -286,7 +286,7 @@ async fn delete_deployment(

Ok(Json(deployment.into()))
} else {
Err(Error::NotFound)
Err(Error::NotFound("deployment not found".to_string()))
}
}

Expand All @@ -305,7 +305,7 @@ async fn get_logs(
.collect(),
))
} else {
Err(Error::NotFound)
Err(Error::NotFound("deployment not found".to_string()))
}
}

Expand Down Expand Up @@ -385,7 +385,7 @@ async fn get_secrets(

Ok(Json(keys))
} else {
Err(Error::NotFound)
Err(Error::NotFound("service not found".to_string()))
}
}

Expand Down

0 comments on commit 4ce62aa

Please sign in to comment.