Skip to content
Browse files

tidied up error handling

  • Loading branch information...
1 parent 97e7267 commit 48a4ebb8c1c1ce6ce978c88591cf29817281e1ed @jaz303 committed Jun 3, 2009
Showing with 21 additions and 8 deletions.
  1. +1 −0 lib/txt_machine.rb
  2. +10 −0 lib/txt_machine/errors.rb
  3. +10 −8 lib/txt_machine/gateways/itagg.rb
View
1 lib/txt_machine.rb
@@ -1,4 +1,5 @@
%w(
+ errors
base
message
gateways/skeleton
View
10 lib/txt_machine/errors.rb
@@ -0,0 +1,10 @@
+module TxtMachine
+ class SendFailedError < RuntimeError
+ attr_reader :wrapped_exception
+
+ def initialize(options = {})
+ super(options[:message])
+ @wrapped_exception = options[:wrapped_exception]
+ end
+ end
+end
View
18 lib/txt_machine/gateways/itagg.rb
@@ -22,20 +22,22 @@ def send(msg)
path += '?' + message_to_hash(msg).map { |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join('&')
begin
+
req = Net::HTTP::Post.new(path)
http = Net::HTTP.new(ENDURI.host, ENDURI.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
res = http.start { |http| http.request(req) }
- rescue => e
-
- end
- case res
- when Net::HTTPSuccess
- # OK
- else
- # error
+ case res
+ when Net::HTTPSuccess
+ # OK
+ else
+ res.error!
+ end
+
+ rescue StandardError => e
+ raise SendFailedError.new(:wrapped_exception => e)
end
end

0 comments on commit 48a4ebb

Please sign in to comment.
Something went wrong with that request. Please try again.