Created
February 5, 2010 22:55
-
-
Save gerad/296353 to your computer and use it in GitHub Desktop.
hoptoad report javascript errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in application.js | |
window.onerror = function(msg, url, line) { | |
var location = String(window.location); | |
new Ajax.Request('/error/error', { | |
method: 'POST', | |
parameters: { | |
message: msg, | |
url: url || location, | |
line: line, | |
location: location, | |
user_agent: navigator.userAgent | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in your controller | |
def error | |
if params[:message] | |
msg = "JavaScript Error: '#{params[:message]}'" | |
path = ActionController::Routing::Routes.recognize_path(URI.parse(params[:location]).path) | |
HoptoadNotifier.notify_or_ignore :error_class => msg, | |
:error_message => msg, | |
:url => params[:location], | |
:controller => path[:controller], | |
:action => path[:id] ? path[:id] : 'show', # TODO lame | |
:cgi_data => request.env, | |
:environment_vars => ENV, | |
:parameters => params | |
end | |
render :nothing => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment