Add custom errors for PDU decoding

develop
Guillaume DOTT 2014-02-10 11:03:44 +01:00
parent e1e7be5d98
commit e34a881ab7
3 changed files with 40 additions and 1 deletions

View File

@ -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 = {})

View File

@ -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

View File

@ -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