diff --git a/lib/biju/pdu.rb b/lib/biju/pdu.rb index 56d63e3..69507c0 100644 --- a/lib/biju/pdu.rb +++ b/lib/biju/pdu.rb @@ -9,6 +9,8 @@ require 'biju/pdu/timestamp' require 'biju/pdu/phone_number' require 'biju/pdu/type_of_address' +require 'biju/pdu/errors' + module Biju module PDU def self.encode(phone_number, message, options = {}) diff --git a/lib/biju/pdu/data_coding_scheme.rb b/lib/biju/pdu/data_coding_scheme.rb index f96a82b..0cfa104 100644 --- a/lib/biju/pdu/data_coding_scheme.rb +++ b/lib/biju/pdu/data_coding_scheme.rb @@ -23,7 +23,7 @@ module Biju if dcs & 0b11000000 == 0 dcs = DATA_CODING_SCHEME.key(dcs & 0b00001100) else - raise 'Unsupported' + raise Biju::PDU::Errors::DataCodingSchemeNotSupported.new(dcs) end end diff --git a/lib/biju/pdu/errors.rb b/lib/biju/pdu/errors.rb new file mode 100644 index 0000000..37fe0cf --- /dev/null +++ b/lib/biju/pdu/errors.rb @@ -0,0 +1,37 @@ +module Biju + module PDU + module Errors + class PDUError < ::StandardError + end + + class MalformedSms < PDUError + attr_reader :original_exception + attr_reader :pdu + + def initialize(pdu, original_exception = nil) + @pdu = pdu + @original_exception = original_exception + end + + def to_s + "This SMS can not be parsed: #{pdu} (#{original_exception.class}: #{original_exception})" + end + end + + class DataCodingSchemeNotSupported < PDUError + attr_reader :data_coding_scheme + + def initialize(dcs = nil) + @data_coding_scheme = dcs + end + + def to_s + "This data coding scheme (0b#{data_coding_scheme.to_s(2)}) is not supported" + end + end + + class EncodingNotSupported < PDUError + end + end + end +end