Skip to content

Commit

Permalink
Merge pull request #1132 from alphagov/add-verbose-logging-for-http-4…
Browse files Browse the repository at this point in the history
…00-errors

Add more explicit & verbose logging when the app sends a HTTP 400
  • Loading branch information
aldavidson authored Aug 23, 2023
2 parents 0a8afa0 + 1036eb6 commit 0ee8c2e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,24 @@ def config
def parse_json_request
# FIXME: base_path in the request body is deprecated and will be considered
# an error once all clients have been updated.
@request_data = JSON.parse(request.body.read).except("base_path")
body = request.body.read
@request_data = JSON.parse(body).except("base_path")
rescue JSON::ParserError
Rails.logger.warn "error parsing JSON from request body '#{body}'"
head :bad_request
end

def encoded_request_path
Addressable::URI.encode(request_path)
rescue Addressable::URI::InvalidURIError
Rails.logger.warn "Can't encode request_path '#{request_path}'"
raise InvalidRequest
end

def encoded_base_path
Addressable::URI.encode(base_path)
rescue Addressable::URI::InvalidURIError
Rails.logger.warn "Can't encode base_path '#{request_path}'"
raise InvalidRequest
end

Expand Down

0 comments on commit 0ee8c2e

Please sign in to comment.