Skip to content

Commit 6554eed

Browse files
committed
Refactor handler loading error messages for clarity and consistency. Bubble up error messages
1 parent 2b4f63d commit 6554eed

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

lib/hooks/app/helpers.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ def load_handler(handler_class_name)
8484
# - Thread Safety: Avoids race conditions from shared instance state
8585
# - Performance: Handler instantiation is fast; reusing instances provides minimal gain
8686
# - Memory: Allows garbage collection of short-lived objects (Ruby GC optimization)
87-
begin
88-
handler_class = Core::PluginLoader.get_handler_plugin(handler_class_name)
89-
return handler_class.new
90-
rescue StandardError => e
91-
error!("failed to get handler '#{handler_class_name}': #{e.message}", 500)
92-
end
87+
handler_class = Core::PluginLoader.get_handler_plugin(handler_class_name)
88+
return handler_class.new
9389
end
9490

9591
private

spec/acceptance/acceptance_tests.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ def expired_unix_timestamp(seconds_ago = 600)
430430
end
431431
end
432432

433+
describe "does_not_exist" do
434+
it "sends a POST request to the /webhooks/does_not_exist endpoint and it fails because the handler does not exist" do
435+
payload = {}.to_json
436+
headers = {}
437+
response = make_request(:post, "/webhooks/does_not_exist", payload, headers)
438+
expect_response(response, Net::HTTPInternalServerError, /Handler plugin 'DoesNotExist' not found/)
439+
body = parse_json_response(response)
440+
expect(body["error"]).to eq("server_error")
441+
expect(body["message"]).to match(
442+
/Handler plugin 'DoesNotExist' not found. Available handlers: DefaultHandler,.*/
443+
)
444+
end
445+
end
446+
433447
describe "okta setup" do
434448
it "sends a POST request to the /webhooks/okta_webhook_setup endpoint and it fails because it is not a GET" do
435449
payload = {}.to_json
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
path: /does_not_exist
2+
handler: DoesNotExist

spec/unit/lib/hooks/app/helpers_security_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def env
3838
it "returns error indicating handler not found" do
3939
expect do
4040
instance.load_handler("NonexistentHandler")
41-
end.to raise_error(StandardError, /failed to get handler.*not found/)
41+
end.to raise_error(StandardError, /Handler plugin.*not found/)
4242
end
4343

4444
it "returns error for any handler class name when no plugins loaded" do
@@ -47,7 +47,7 @@ def env
4747
handler_names.each do |name|
4848
expect do
4949
instance.load_handler(name)
50-
end.to raise_error(StandardError, /failed to get handler.*not found/)
50+
end.to raise_error(StandardError, /Handler plugin.*not found/)
5151
end
5252
end
5353
end

spec/unit/lib/hooks/app/helpers_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def error!(message, code)
296296
it "returns error indicating handler not found" do
297297
expect do
298298
helper.load_handler("NonexistentHandler")
299-
end.to raise_error(StandardError, /failed to get handler.*not found/)
299+
end.to raise_error(StandardError, /Handler plugin.*not found/)
300300
end
301301
end
302302

0 commit comments

Comments
 (0)