diff --git a/lib/sdf-server/src/server/service/func.rs b/lib/sdf-server/src/server/service/func.rs index e2aee2cb73..7ddf3636e9 100644 --- a/lib/sdf-server/src/server/service/func.rs +++ b/lib/sdf-server/src/server/service/func.rs @@ -1,5 +1,7 @@ +use crate::server::state::AppState; +use axum::http::StatusCode; use axum::{ - response::Response, + response::{IntoResponse, Response}, routing::{get, post}, Json, Router, }; @@ -15,8 +17,6 @@ use dal::{ChangeSetError, WsEventError}; use si_layer_cache::LayerDbError; use thiserror::Error; -use crate::server::{impl_default_error_into_response, state::AppState}; - pub mod create_attribute_prototype; pub mod create_func; pub mod create_func_argument; @@ -78,7 +78,17 @@ pub enum FuncError { pub type FuncResult = Result; -impl_default_error_into_response!(FuncError); +impl IntoResponse for FuncError { + fn into_response(self) -> Response { + let (status, error_message) = (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()); + + let body = Json( + serde_json::json!({ "error": { "message": error_message, "code": 42, "statusCode": status.as_u16() } }), + ); + + (status, body).into_response() + } +} pub fn routes() -> Router { Router::new() diff --git a/lib/sdf-server/src/server/service/module.rs b/lib/sdf-server/src/server/service/module.rs index 1f562289e6..9bbb3c8a8f 100644 --- a/lib/sdf-server/src/server/service/module.rs +++ b/lib/sdf-server/src/server/service/module.rs @@ -1,6 +1,7 @@ -use crate::server::{impl_default_error_into_response, state::AppState}; +use crate::server::state::AppState; +use axum::http::StatusCode; use axum::{ - response::Response, + response::{IntoResponse, Response}, routing::{get, post}, Json, Router, }; @@ -121,7 +122,25 @@ pub enum ModuleError { pub type ModuleResult = Result; -impl_default_error_into_response!(ModuleError); +impl IntoResponse for ModuleError { + fn into_response(self) -> Response { + let (status, error_message) = match self { + ModuleError::ChangeSetNotFound(_) + | ModuleError::ModuleHashNotFound(_) + | ModuleError::PackageNotFound(_) + | ModuleError::SchemaNotFoundForVariant(_) + | ModuleError::SchemaVariantNotFound(_) + | ModuleError::WorkspaceNotFound(_) => (StatusCode::NOT_FOUND, self.to_string()), + _ => (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()), + }; + + let body = Json( + serde_json::json!({ "error": { "message": error_message, "code": 42, "statusCode": status.as_u16() } }), + ); + + (status, body).into_response() + } +} #[derive(Deserialize, Serialize, Debug)] #[serde(rename_all = "camelCase")]