lib/include/class_knjappserver_errors.rb in knjappserver-0.0.15 vs lib/include/class_knjappserver_errors.rb in knjappserver-0.0.16
- old
+ new
@@ -16,10 +16,11 @@
self.timeout(:time => @error_emails_time) do
self.flush_error_emails
end
end
+ #Send error-emails based on error-emails-cache (cached so the same error isnt send out every time it occurrs to prevent spamming).
def flush_error_emails
@error_emails_pending_mutex.synchronize do
send_time_older_than = Time.new.to_i - @error_emails_time
@error_emails_pending.each do |backtrace_hash, error_email|
@@ -63,10 +64,11 @@
@error_emails_pending.delete(backtrace_hash)
end
end
end
+ #Handels a given error. Sends to the admin-emails.
def handle_error(e, args = {})
@error_emails_pending_mutex.synchronize do
if !Thread.current[:knjappserver] or !Thread.current[:knjappserver][:httpsession]
STDOUT.print "Error: "
STDOUT.puts e.inspect
@@ -80,11 +82,11 @@
if !@error_emails_pending.has_key?(backtrace_hash)
@error_emails_pending[backtrace_hash] = {
:first_time => Time.new,
:messages => [],
- :subject => sprintf("Error @ %s", @config[:title]) + " (#{e.message})"
+ :subject => sprintf("Error @ %s", @config[:title]) + " (#{Knj::Strings.shorten(e.message, 100)})"
}
end
html = "An error occurred.<br /><br />"
html += "<b>#{e.class.name.html}: #{e.message.html}</b><br /><br />"
@@ -105,9 +107,10 @@
error_hash[:messages] << html
end
end
end
+ #Takes a proc and executes it. On error it alerts the error-message with javascript to the server, sends a javascript back and exits.
def on_error_go_back(&block)
begin
block.call
rescue => e
self.alert(e.message).back
\ No newline at end of file