Skip to content

Commit

Permalink
Improvements to error handling for support ticket configuration (OSC#…
Browse files Browse the repository at this point in the history
  • Loading branch information
abujeda authored Sep 5, 2023
1 parent 5094004 commit e775eb2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apps/dashboard/app/controllers/support_ticket_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def new
@support_ticket = support_service.default_support_ticket(params)

render get_ui_template

rescue StandardError => e
logger.error "Could not render support ticket page. Error=#{e}"
redirect_to root_url, :flash => { :alert => t('dashboard.support_ticket.generic_error', error: e) }
end

# POST /support
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/models/user_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def support_ticket_service
return SupportTicketEmailService.new(support_ticket) if support_ticket[:email]
return SupportTicketRtService.new(support_ticket) if support_ticket[:rt_api]

raise StandardError, 'No support ticket service class configured'
raise StandardError, I18n.t('dashboard.user_configuration.support_ticket_error')
end

# The current user profile. Used to select the configuration properties.
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ en:

settings_updated: "Settings updated"

user_configuration:
support_ticket_error: "support_ticket is misconfigured. \"email\" or \"rt_api\" sections are required in the configuration YAML."

breadcrumbs_support_ticket: "Support Ticket"
support_ticket:
title: "Support Ticket"
Expand Down
15 changes: 15 additions & 0 deletions apps/dashboard/test/controllers/support_ticket_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ def set_support_ticket_config(config)
assert_equal support_ticket_mock, @controller.instance_variable_get(:@support_ticket)
end

test "new should log error and redirect to root when exception is raised" do
# Configure support without service to throw exception
set_support_ticket_config({})
I18n.expects(:t).with('dashboard.user_configuration.support_ticket_error').returns('user configuration message')
expected_log_message = 'Could not render support ticket page. Error=user configuration message'

# We expect to log the error
logger_stub = stub('logger').tap { |s| s.expects(:error).with(expected_log_message) }
@controller.stubs(:logger).returns(logger_stub)
@controller.expects(:t).with('dashboard.support_ticket.generic_error', anything).returns('controller error')
@controller.expects(:redirect_to).with('/home', flash: { alert: 'controller error' })

@controller.new
end

test "create should delegate to service class to validate and create ticket, then redirect to homepage" do
# Configure the SupportTicketEmailService
set_support_ticket_config({ email: {} })
Expand Down

0 comments on commit e775eb2

Please sign in to comment.