Skip to content

Instantly share code, notes, and snippets.

@gerad
Created February 5, 2010 22:55
Show Gist options
  • Save gerad/296353 to your computer and use it in GitHub Desktop.
Save gerad/296353 to your computer and use it in GitHub Desktop.
hoptoad report javascript errors
// 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
}
});
}
# 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