From f8ea1fb4f7ec2bf417eb17b3869c9519b36acdd5 Mon Sep 17 00:00:00 2001 From: Sergey Savelyev Date: Sat, 3 Jan 2026 00:44:20 -0500 Subject: [PATCH] cleanup --- api-core/src/command.rs | 13 +++++++++++++ .../components/CommandParameterListConfigurator.vue | 7 ++++++- frontend/src/composables/command.ts | 9 +++++++-- frontend/src/composables/json.ts | 2 ++ server/src/http/api/cmd.rs | 6 +++++- server/src/http/error.rs | 3 +++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/api-core/src/command.rs b/api-core/src/command.rs index e8a210e..ea17322 100644 --- a/api-core/src/command.rs +++ b/api-core/src/command.rs @@ -45,3 +45,16 @@ pub trait IntoCommandDefinition: Sized { fn parse(command: Command) -> Result; } + +impl IntoCommandDefinition for () { + fn create(name: String) -> CommandDefinition { + CommandDefinition { + name, + parameters: vec![], + } + } + + fn parse(_: Command) -> Result { + Ok(()) + } +} diff --git a/frontend/src/components/CommandParameterListConfigurator.vue b/frontend/src/components/CommandParameterListConfigurator.vue index b9f9b80..f5a76c0 100644 --- a/frontend/src/components/CommandParameterListConfigurator.vue +++ b/frontend/src/components/CommandParameterListConfigurator.vue @@ -19,7 +19,9 @@ const model = defineModel<{ [key: string]: CommandParameterData }>({ required: true, }); -const { data: command_info } = useCommand(props.command_name); +const { data: command_info, error: command_error } = useCommand( + props.command_name, +); watch([command_info], ([cmd_info]) => { if (cmd_info == null) { @@ -97,6 +99,9 @@ watch([command_info], ([cmd_info]) => { > + diff --git a/frontend/src/composables/command.ts b/frontend/src/composables/command.ts index 4798dc8..06167f5 100644 --- a/frontend/src/composables/command.ts +++ b/frontend/src/composables/command.ts @@ -41,8 +41,13 @@ export function useCommand(name: MaybeRefOrGetter) { try { const res = await fetch(`/api/cmd/${name_value}`); - data.value = await res.json(); - error.value = null; + if (res.ok) { + data.value = await res.json(); + error.value = null; + } else { + data.value = null; + error.value = await res.text(); + } } catch (e) { data.value = null; error.value = e; diff --git a/frontend/src/composables/json.ts b/frontend/src/composables/json.ts index d01a516..0e63f14 100644 --- a/frontend/src/composables/json.ts +++ b/frontend/src/composables/json.ts @@ -2,6 +2,7 @@ export function toJsonString(data: any): string { return JSON.stringify(data, (_key, value) => { if (typeof value == 'bigint') { + // @ts-expect-error TS2339 return JSON.rawJSON(value.toString()); } return value; @@ -10,6 +11,7 @@ export function toJsonString(data: any): string { // eslint-disable-next-line @typescript-eslint/no-explicit-any export function parseJsonString(data: string): any { + // @ts-expect-error TS2345, TS7006 return JSON.parse(data, (key, value, context) => { if (key === 'Int64' || key == 'Unsigned64') { // Or use the constructor of your custom high-precision number library diff --git a/server/src/http/api/cmd.rs b/server/src/http/api/cmd.rs index d9f61ea..8eccd57 100644 --- a/server/src/http/api/cmd.rs +++ b/server/src/http/api/cmd.rs @@ -29,6 +29,10 @@ pub(super) async fn get_one( name: web::Path, ) -> Result { Ok(web::Json( - command_service.get_command_definition(&name.to_string()), + command_service + .get_command_definition(&name.to_string()) + .ok_or_else(|| HttpServerResultError::CmdNotFound { + cmd: name.to_string(), + })?, )) } diff --git a/server/src/http/error.rs b/server/src/http/error.rs index a37fff9..3ce54fb 100644 --- a/server/src/http/error.rs +++ b/server/src/http/error.rs @@ -23,6 +23,8 @@ pub enum HttpServerResultError { PanelUuidNotFound { uuid: Uuid }, #[error(transparent)] Command(#[from] crate::command::error::Error), + #[error("Command Not Found: {cmd}")] + CmdNotFound { cmd: String }, } impl ResponseError for HttpServerResultError { @@ -36,6 +38,7 @@ impl ResponseError for HttpServerResultError { HttpServerResultError::InternalError { .. } => StatusCode::INTERNAL_SERVER_ERROR, HttpServerResultError::PanelUuidNotFound { .. } => StatusCode::NOT_FOUND, HttpServerResultError::Command(inner) => inner.status_code(), + HttpServerResultError::CmdNotFound { .. } => StatusCode::NOT_FOUND, } } fn error_response(&self) -> HttpResponse {