Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ def squash_multiparameter_datetime_attributes(params, attribute_names)
end

def notify_bad_request(exception)
# TODO: control this via the log level rather than an environment variable
if %w[integration staging].include?(ENV["GOVUK_ENVIRONMENT"]) && exception.message =~ /team-only API key/
# in production we care about all errors
# in staging and integration the team-only error may be encountered by
# end-users who should see a more helpful error message
raise
else
# If we use a team-only Notify API key in future for staging and integration
# the team-only error may be encountered, this logs a more helpful message
if GovukEnvironment.current != "production" && exception.message =~ /team-only API key/
error = <<~ERROR
Error: One or more recipients not in GOV.UK Notify team (code: 400).
This error will not occur in Production.
ERROR

render plain: error, status: :bad_request
Rails.logger.error("#{error}, code: #{exception.code}")
else
raise
end
end

Expand Down
24 changes: 0 additions & 24 deletions test/integration/legacy_edition_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,30 +258,6 @@ class LegacyEditionWorkflowTest < LegacyJavascriptIntegrationTest
assert_equal "Blah blah fact check message", resent_fact_check_email.body.to_s
end

test "sending a fact check email to a non-permitted address will return an error" do
raises_exception = lambda { |_request, _params|
response = Minitest::Mock.new
response.expect :code, 400
response.expect :body, "Can't send to this recipient using a team-only API key"
raise Notifications::Client::BadRequestError, response
}

EventMailer.stub(:request_fact_check, raises_exception) do
@simple_smart_answer.update!(state: "ready")
visit_edition @simple_smart_answer

click_link("Fact check")

within "#send_fact_check_form" do
fill_in "Customised message", with: "Blah blah fact check message"
fill_in "Email address", with: "user-to-ask-for-fact-check@example.com"
click_on "Send"
end

assert page.has_content? "Error: One or more recipients not in GOV.UK Notify team (code: 400).\nThis error will not occur in Production."
end
end

should "be able to send simple smart answer for review" do
@simple_smart_answer.assigned_to = bob

Expand Down
Loading