From 0ff984ddddcc20127d7af0f9eb481e72116c115b Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 13 May 2025 11:43:38 +0200 Subject: [PATCH] Handle errors in composite commands --- app/controllers/commands_controller.rb | 10 ++++++++-- app/models/command/composite.rb | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/commands_controller.rb b/app/controllers/commands_controller.rb index 66d5a78b0..ccb187cc3 100644 --- a/app/controllers/commands_controller.rb +++ b/app/controllers/commands_controller.rb @@ -15,7 +15,7 @@ class CommandsController < ApplicationController respond_with_needs_confirmation(command) end else - head :unprocessable_entity + respond_with_error end end @@ -55,9 +55,11 @@ class CommandsController < ApplicationController if confirmed?(command) if result.has_context_url? && params["redirected"].blank? respond_with_needs_redirection redirect_to: result.context_url - else + elsif command.valid? chat_response_result = command.execute respond_with_execution_result chat_response_result + else + respond_with_error end else respond_with_needs_confirmation(command.commands, redirect_to: result.context_url) @@ -81,4 +83,8 @@ class CommandsController < ApplicationController def respond_with_insight_response(chat_response) render json: { message: chat_response.content }, status: :accepted end + + def respond_with_error + head :unprocessable_entity + end end diff --git a/app/models/command/composite.rb b/app/models/command/composite.rb index da79e2280..7efcc4e47 100644 --- a/app/models/command/composite.rb +++ b/app/models/command/composite.rb @@ -28,6 +28,10 @@ class Command::Composite commands.any?(&:needs_confirmation?) end + def valid? + commands.all?(&:valid?) + end + private def undoable_commands commands.filter(&:undoable?)