Skip to content

Commit

Permalink
Don't rely on anything but Rack spec when modifying in the Informer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Mar 22, 2011
1 parent 2f484b5 commit beea218
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -228,6 +228,26 @@ To perform custom error processing after Hoptoad has been notified, define the
instance method #rescue_action_in_public_without_hoptoad(exception) in your
controller.

Informing the User
------------------

The Notifier gem is capable of telling the user information about the error that just happened
via the user_informer option. They can give this error number in bug resports, for example.
By default, if your 500.html contains the text

<!-- HOPTOAD ERROR -->

then that comment will be replaced with the text "Hoptoad Error [errnum]". You can modify the text
of the informer by setting config.user_informer. The Notifier will replace "{{ error_id }}" with the
ID of the error that is returned from Hoptoad.

HoptoadNotifier.configure do |config|
...
config.user_informer = "<p>Tell the devs that it was <strong>{{ error_id }}</strong>'s fault.</p>"
end

You can also turn the middleware completely off by setting config.user_informer to false.

Tracking deployments in Hoptoad
-------------------------------

Expand Down
21 changes: 21 additions & 0 deletions features/user_informer.feature
Expand Up @@ -40,3 +40,24 @@ 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 "Error #3799307"

Scenario: Don't inform them user
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 = false
"""
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 not see "Hoptoad Error 3799307"
10 changes: 6 additions & 4 deletions lib/hoptoad_notifier/user_informer.rb
Expand Up @@ -10,11 +10,13 @@ def replacement(with)

def call(env)
status, headers, body = @app.call(env)
if env['hoptoad.error_id']
body.each_with_index do |chunk, i|
body[i] = chunk.to_s.gsub("<!-- HOPTOAD ERROR -->", replacement(env['hoptoad.error_id']))
if env['hoptoad.error_id'] && HoptoadNotifier.configuration.user_information
new_body = []
body.each do |chunk|
new_body << chunk.gsub("<!-- HOPTOAD ERROR -->", replacement(env['hoptoad.error_id']))
end
headers['Content-Length'] = body.sum(&:length).to_s
headers['Content-Length'] = new_body.sum(&:length).to_s
body = new_body
end
[status, headers, body]
end
Expand Down

0 comments on commit beea218

Please sign in to comment.