blob: 7bb9238ad34a4bc0773d8f9f7533e829fdbbc575 [file] [log] [blame]
Kevin Clark97d21662008-06-18 00:53:28 +00001module Thrift
2 class Exception < StandardError
3 def initialize(message)
Kevin Clarke12b0f82008-06-18 00:58:58 +00004 super
Kevin Clark97d21662008-06-18 00:53:28 +00005 @message = message
6 end
7
8 attr_reader :message
Kevin Clark9bf33622008-06-18 00:53:07 +00009 end
Kevin Clarkc42231b2008-06-18 00:56:30 +000010 deprecate_class! :TException => Exception
Kevin Clark9bf33622008-06-18 00:53:07 +000011
Kevin Clark97d21662008-06-18 00:53:28 +000012 class ApplicationException < Exception
Kevin Clark9bf33622008-06-18 00:53:07 +000013
Kevin Clark97d21662008-06-18 00:53:28 +000014 UNKNOWN = 0
15 UNKNOWN_METHOD = 1
16 INVALID_MESSAGE_TYPE = 2
17 WRONG_METHOD_NAME = 3
18 BAD_SEQUENCE_ID = 4
19 MISSING_RESULT = 5
Kevin Clark9bf33622008-06-18 00:53:07 +000020
Kevin Clark97d21662008-06-18 00:53:28 +000021 attr_reader :type
Kevin Clark9bf33622008-06-18 00:53:07 +000022
Kevin Clark97d21662008-06-18 00:53:28 +000023 def initialize(type=UNKNOWN, message=nil)
Kevin Clark95833c52008-06-18 01:04:34 +000024 super(message)
Kevin Clark97d21662008-06-18 00:53:28 +000025 @type = type
26 end
Kevin Clark9bf33622008-06-18 00:53:07 +000027
Kevin Clark97d21662008-06-18 00:53:28 +000028 def read(iprot)
Kevin Clarkd389f542008-06-18 01:11:41 +000029 iprot.read_struct_begin
Kevin Clark97d21662008-06-18 00:53:28 +000030 while true
Kevin Clarkd389f542008-06-18 01:11:41 +000031 fname, ftype, fid = iprot.read_field_begin
Kevin Clark5a2d0ad2008-06-18 01:14:48 +000032 if ftype == Types::STOP
Kevin Clark97d21662008-06-18 00:53:28 +000033 break
34 end
Kevin Clark5a2d0ad2008-06-18 01:14:48 +000035 if fid == 1 and ftype == Types::STRING
36 @message = iprot.read_string
37 elsif fid == 2 and ftype == Types::I32
38 @type = iprot.read_i32
Kevin Clark9bf33622008-06-18 00:53:07 +000039 else
40 iprot.skip(ftype)
41 end
Kevin Clarkd389f542008-06-18 01:11:41 +000042 iprot.read_field_end
Kevin Clark9bf33622008-06-18 00:53:07 +000043 end
Kevin Clarkd389f542008-06-18 01:11:41 +000044 iprot.read_struct_end
Kevin Clark9bf33622008-06-18 00:53:07 +000045 end
Kevin Clark9bf33622008-06-18 00:53:07 +000046
Kevin Clark97d21662008-06-18 00:53:28 +000047 def write(oprot)
Kevin Clark89437882008-06-18 00:59:17 +000048 oprot.write_struct_begin('Thrift::ApplicationException')
Kevin Clark5a2d0ad2008-06-18 01:14:48 +000049 unless @message.nil?
Kevin Clark89437882008-06-18 00:59:17 +000050 oprot.write_field_begin('message', Types::STRING, 1)
51 oprot.write_string(@message)
Kevin Clarkd389f542008-06-18 01:11:41 +000052 oprot.write_field_end
Kevin Clark97d21662008-06-18 00:53:28 +000053 end
Kevin Clark5a2d0ad2008-06-18 01:14:48 +000054 unless @type.nil?
Kevin Clark89437882008-06-18 00:59:17 +000055 oprot.write_field_begin('type', Types::I32, 2)
56 oprot.write_i32(@type)
Kevin Clarkd389f542008-06-18 01:11:41 +000057 oprot.write_field_end
Kevin Clark97d21662008-06-18 00:53:28 +000058 end
Kevin Clarkd389f542008-06-18 01:11:41 +000059 oprot.write_field_stop
60 oprot.write_struct_end
Kevin Clark9bf33622008-06-18 00:53:07 +000061 end
Kevin Clark9bf33622008-06-18 00:53:07 +000062
Kevin Clark97d21662008-06-18 00:53:28 +000063 end
Kevin Clarkc42231b2008-06-18 00:56:30 +000064 deprecate_class! :TApplicationException => ApplicationException
Kevin Clark97d21662008-06-18 00:53:28 +000065end