Handle errors in composite commands

This commit is contained in:
Jorge Manrubia
2025-05-13 11:43:38 +02:00
parent 04ee9925e7
commit 0ff984dddd
2 changed files with 12 additions and 2 deletions
+8 -2
View File
@@ -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
+4
View File
@@ -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?)