Skip to content

Commit a9e4f91

Browse files
committed
Fix exception handler for Notify errors in ApplicationController
- Logic for this contradicted the comment and would surely result in exceptions being raised in non-prod environments - User (dev) friendly 'Team only key' errors would be raised in prod, not in staging or integration
1 parent 557e136 commit a9e4f91

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

app/controllers/application_controller.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,17 @@ def squash_multiparameter_datetime_attributes(params, attribute_names)
3434
end
3535

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

49-
render plain: error, status: :bad_request
45+
Rails.logger.error("#{error}, code: #{exception.code}")
46+
else
47+
raise
5048
end
5149
end
5250

0 commit comments

Comments
 (0)