Class: MarchHare::Exceptions
- Inherits:
-
Object
- Object
- MarchHare::Exceptions
- Defined in:
- lib/march_hare/exceptions.rb
Overview
Converts RabbitMQ Java client exceptions
Class Method Summary collapse
- .convert(e, unwrap_io_exception = true) ⇒ Object
- .convert_and_reraise(e) ⇒ Object
- .exception_for_channel_close(m) ⇒ Object
- .exception_for_connection_close(m) ⇒ Object
- .exception_for_protocol_method(m) ⇒ Object
Class Method Details
.convert(e, unwrap_io_exception = true) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/march_hare/exceptions.rb', line 99 def self.convert(e, unwrap_io_exception = true) case e when java.net.SocketException then IOError.new when java.io.IOException then c = e.cause if c && unwrap_io_exception convert(c, false) else IOError.new end when com.rabbitmq.client.AlreadyClosedException then ChannelAlreadyClosed.new(e.reason) when com.rabbitmq.client.ShutdownSignalException then exception_for_protocol_method(e.reason) else e end end |
.convert_and_reraise(e) ⇒ Object
120 121 122 |
# File 'lib/march_hare/exceptions.rb', line 120 def self.convert_and_reraise(e) raise convert(e) end |
.exception_for_channel_close(m) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/march_hare/exceptions.rb', line 158 def self.exception_for_channel_close(m) klass = case m.reply_code when 403 then AccessRefused when 404 then NotFound when 405 then ResourceLocked when 406 then PreconditionFailed else ChannelLevelException end klass.new(m.reply_text, m) end |
.exception_for_connection_close(m) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/march_hare/exceptions.rb', line 139 def self.exception_for_connection_close(m) klass = case m.reply_code when 320 then ConnectionForced when 501 then FrameError when 503 then InvalidCommand when 504 then ChannelError when 505 then UnexpectedFrame else raise "Unknown reply code: #{m.reply_code}, text: #{m.reply_text}" end klass.new("Connection-level error: #{m.reply_text}", m) end |
.exception_for_protocol_method(m) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/march_hare/exceptions.rb', line 124 def self.exception_for_protocol_method(m) case m # com.rabbitmq.client.AMQP.Connection.Close does not resolve the inner # class correctly. Looks like a JRuby bug we work around by using Rubyesque # class name. MK. when Java::ComRabbitmqClient::AMQP::Connection::Close then exception_for_connection_close(m) when Java::ComRabbitmqClient::AMQP::Channel::Close then exception_for_channel_close(m) else NotImplementedError.new("Exception convertion for protocol method #{m.inspect} is not implemented!") end end |