Permalink
Browse files

Make the text presented to the user customizable

  • Loading branch information...
1 parent 68f51a4 commit d65531c257b6ef735f7374398053fa62bbe0a5d5 @jyurek jyurek committed Jan 24, 2011
@@ -18,4 +18,25 @@ Feature: Inform the user of the hoptoad notice that was just created
"""
And I route "/test/index" to "test#index"
And I perform a request to "http://example.com:123/test/index?param=value"
+ Then I should see "Hoptoad Error 3799307"
+
+ Scenario: Rescue an exception in a controller with a custom error string
+ When I generate a new Rails application
+ And I configure the Hoptoad shim
+ And I configure my application to require the "hoptoad_notifier" gem
+ And I configure the notifier to use the following configuration lines:
+ """
+ config.user_information = "Error #{{ error_id }}"
+ """
+ And I run the hoptoad generator with "-k myapikey"
+ And I define a response for "TestController#index":
+ """
+ raise RuntimeError, "some message"
+ """
+ And the response page for a "500" error is
+ """
+ <!-- HOPTOAD ERROR -->
+ """
+ And I route "/test/index" to "test#index"
+ And I perform a request to "http://example.com:123/test/index?param=value"
Then I should see "Error #3799307"
@@ -7,7 +7,8 @@ class Configuration
:http_open_timeout, :http_read_timeout, :ignore, :ignore_by_filters,
:ignore_user_agent, :notifier_name, :notifier_url, :notifier_version,
:params_filters, :project_root, :port, :protocol, :proxy_host,
- :proxy_pass, :proxy_port, :proxy_user, :secure, :framework, :js_notifier].freeze
+ :proxy_pass, :proxy_port, :proxy_user, :secure, :framework,
+ :js_notifier, :user_information].freeze
# The API key for your project, found on the project edit form.
attr_accessor :api_key
@@ -83,6 +84,9 @@ class Configuration
# The logger used by HoptoadNotifier
attr_accessor :logger
+ # The text that the placeholder is replaced with. {{error_id}} is the actual error number.
+ attr_accessor :user_information
+
# The framework HoptoadNotifier is configured to use
attr_accessor :framework
@@ -133,6 +137,7 @@ def initialize
@notifier_version = VERSION
@notifier_url = 'http://hoptoadapp.com'
@framework = 'Standalone'
+ @user_information = 'Hoptoad Error {{error_id}}'
end
# Takes a block and adds it to the list of backtrace filters. When the filters
@@ -4,6 +4,10 @@ def initialize(app)
@app = app
end
+ def replacement(with)
+ @replacement ||= HoptoadNotifier.configuration.user_information.gsub(/\{\{\s*error_id\s*\}\}/, with.to_s)
+ end
+
def call(env)
response = @app.call(env)
if env['hoptoad.error_id']
@@ -12,7 +16,7 @@ def call(env)
modified_content_length = 0
response[2].each do |chunk|
original_content_length += chunk.length
- new_response << chunk.to_s.gsub("<!-- HOPTOAD ERROR -->", "Error ##{env["hoptoad.error_id"].to_s}")
+ new_response << chunk.to_s.gsub("<!-- HOPTOAD ERROR -->", replacement(env['hoptoad.error_id']))
modified_content_length += new_response.last.length
end
response[1]['Content-Length'] = modified_content_length.to_s
@@ -11,8 +11,8 @@ class UserInformerTest < Test::Unit::TestCase
ShamRack.mount(informer_app, "example.com")
response = Net::HTTP.get_response(URI.parse("http://example.com/"))
- assert_equal "Error #1", response.body
- assert_equal 8, response["Content-Length"].to_i
+ assert_equal "Hoptoad Error 1", response.body
+ assert_equal 15, response["Content-Length"].to_i
end
should "not modify output if there is no hoptoad id" do

0 comments on commit d65531c

Please sign in to comment.