From fa7a4aa099beb7dda2b7ebe791b5c9207561977b Mon Sep 17 00:00:00 2001 From: Brit Myers Date: Mon, 15 Jul 2024 16:55:02 -0400 Subject: [PATCH] fix(sdf): return 404 if the func is not found in the requested changeset --- lib/sdf-server/src/server/service/v2/func.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/sdf-server/src/server/service/v2/func.rs b/lib/sdf-server/src/server/service/v2/func.rs index fe4359b7a0..72edf1afb7 100644 --- a/lib/sdf-server/src/server/service/v2/func.rs +++ b/lib/sdf-server/src/server/service/v2/func.rs @@ -43,6 +43,8 @@ pub enum FuncAPIError { FuncBinding(#[from] FuncBindingError), #[error("The function name \"{0}\" is reserved")] FuncNameReserved(String), + #[error("The function does not exist")] + FuncNotFound(FuncId), #[error("hyper error: {0}")] Http(#[from] axum::http::Error), #[error("missing action kind")] @@ -96,6 +98,8 @@ impl IntoResponse for FuncAPIError { Self::Transactions(dal::TransactionsError::ConflictsOccurred(_)) => { StatusCode::CONFLICT } + // Return 404 when the func is not found + Self::FuncNotFound(_) => StatusCode::NOT_FOUND, // When a graph node cannot be found for a schema variant, it is not found Self::SchemaVariant(dal::SchemaVariantError::NotFound(_)) => StatusCode::NOT_FOUND, _ => ApiError::DEFAULT_ERROR_STATUS_CODE, @@ -156,7 +160,9 @@ pub fn v2_routes() -> Router { // helper to assemble the front end struct to return the code and types so SDF can decide when these events need to fire pub async fn get_code_response(ctx: &DalContext, func_id: FuncId) -> FuncAPIResult { - let func = Func::get_by_id_or_error(ctx, func_id).await?; + let func = Func::get_by_id(ctx, func_id) + .await? + .ok_or(FuncAPIError::FuncNotFound(func_id))?; let code = func.code_plaintext()?.unwrap_or("".to_string()); Ok(FuncCode { func_id: func.id.into(),