mirror of
https://github.com/moparisthebest/mailcatcher
synced 2024-12-22 07:18:53 -05:00
Catch errors during websocket send
Tidy up the error handling code a little, and substitute out gem paths.
This commit is contained in:
parent
132f1c0f42
commit
e8531da70d
@ -60,6 +60,17 @@ module MailCatcher extend self
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_exception(message, context, exception)
|
||||||
|
gems_paths = (Gem.path | [Gem.default_dir]).map { |path| Regexp.escape(path) }
|
||||||
|
gems_regexp = %r{(?:#{gems_paths.join('|')})/gems/([^/]+)-([\w.]+)/(.*)}
|
||||||
|
gems_replace = '\1 (\2) \3'
|
||||||
|
|
||||||
|
puts "*** #{message}: #{context.inspect}"
|
||||||
|
puts " Exception: #{exception}"
|
||||||
|
puts " Backtrace:", *exception.backtrace.map { |line| " #{line.sub(gems_regexp, gems_replace)}" }
|
||||||
|
puts " Please submit this as an issue at http://github.com/sj26/mailcatcher/issues"
|
||||||
|
end
|
||||||
|
|
||||||
@@defaults = {
|
@@defaults = {
|
||||||
:smtp_ip => '127.0.0.1',
|
:smtp_ip => '127.0.0.1',
|
||||||
:smtp_port => '1025',
|
:smtp_port => '1025',
|
||||||
|
@ -46,14 +46,8 @@ class MailCatcher::Smtp < EventMachine::Protocols::SmtpServer
|
|||||||
MailCatcher::Mail.add_message current_message
|
MailCatcher::Mail.add_message current_message
|
||||||
puts "==> SMTP: Received message from '#{current_message[:sender]}' (#{current_message[:source].length} bytes)"
|
puts "==> SMTP: Received message from '#{current_message[:sender]}' (#{current_message[:source].length} bytes)"
|
||||||
true
|
true
|
||||||
rescue
|
rescue => exception
|
||||||
puts "*** Error receiving message: #{current_message.inspect}"
|
MailCatcher.log_exception("Error receiving message", @current_message, exception)
|
||||||
puts " Exception: #{$!}"
|
|
||||||
puts " Backtrace:"
|
|
||||||
$!.backtrace.each do |line|
|
|
||||||
puts " #{line}"
|
|
||||||
end
|
|
||||||
puts " Please submit this as an issue at http://github.com/sj26/mailcatcher/issues"
|
|
||||||
false
|
false
|
||||||
ensure
|
ensure
|
||||||
@current_message = nil
|
@current_message = nil
|
||||||
|
@ -64,8 +64,15 @@ module MailCatcher
|
|||||||
if request.websocket?
|
if request.websocket?
|
||||||
request.websocket!(
|
request.websocket!(
|
||||||
:on_start => proc do |websocket|
|
:on_start => proc do |websocket|
|
||||||
subscription = Events::MessageAdded.subscribe { |message| websocket.send_message(JSON.generate(message)) }
|
subscription = Events::MessageAdded.subscribe do |message|
|
||||||
websocket.on_close do |websocket|
|
begin
|
||||||
|
websocket.send_message(JSON.generate(message))
|
||||||
|
rescue => exception
|
||||||
|
MailCatcher.log_exception("Error sending message through websocket", message, exception)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
websocket.on_close do |*|
|
||||||
Events::MessageAdded.unsubscribe subscription
|
Events::MessageAdded.unsubscribe subscription
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user