Add custom errors for PDU decoding
parent
e1e7be5d98
commit
e34a881ab7
|
@ -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 = {})
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue