mirror of
https://github.com/discourse/discourse.git
synced 2026-08-02 09:29:37 -05:00
DEV: gracefully handle missing parameters (#37705)
Avoid a 500 error when params are missing
This commit is contained in:
@@ -101,7 +101,7 @@ module DiscourseAi
|
||||
|
||||
def test
|
||||
@ai_tool.assign_attributes(ai_tool_params) if params[:ai_tool]
|
||||
parameters = params[:parameters].to_unsafe_h
|
||||
parameters = params[:parameters]&.to_unsafe_h || {}
|
||||
|
||||
# we need an llm so we have a tokenizer
|
||||
# but will do without if none is available
|
||||
|
||||
@@ -385,6 +385,13 @@ RSpec.describe DiscourseAi::Admin::AiToolsController do
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "handles missing parameters gracefully" do
|
||||
post "/admin/plugins/discourse-ai/ai-tools/#{ai_tool.id}/test.json", params: {}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["output"]).to eq({})
|
||||
end
|
||||
|
||||
it "handles exceptions during tool execution" do
|
||||
ai_tool.update!(script: "function invoke(params) { throw new Error('Test error'); }")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user