@@ -307,6 +307,10 @@ def set_query_resp_handler(self, func):
307307 """Set new function to handle query resp event"""
308308 self .query_resp_handler = func
309309
310+ def set_error_pdu_handler (self , func ):
311+ """Set new function to handle PDUs with an error status"""
312+ self .error_pdu_handler = func
313+
310314 def message_received_handler (self , pdu , ** kwargs ):
311315 """Custom handler to process received message. May be overridden"""
312316 self .logger .warning ('Message received handler (Override me)' )
@@ -322,6 +326,14 @@ def query_resp_handler(self, pdu, **kwargs):
322326 """Custom handler to process response to queries. May be overridden"""
323327 self .logger .warning ('Query resp handler (Override me)' )
324328
329+ def error_pdu_handler (self , pdu ):
330+ raise exceptions .PDUError ('({}) {}: {}' .format (
331+ pdu .status ,
332+ pdu .command ,
333+ consts .DESCRIPTIONS .get (pdu .status , 'Unknown status' )),
334+ int (pdu .status ),
335+ )
336+
325337 def read_once (self , ignore_error_codes = None , auto_send_enquire_link = True ):
326338 """Read a PDU and act"""
327339 try :
@@ -336,12 +348,7 @@ def read_once(self, ignore_error_codes=None, auto_send_enquire_link=True):
336348 return
337349
338350 if pdu .is_error ():
339- raise exceptions .PDUError ('({}) {}: {}' .format (
340- pdu .status ,
341- pdu .command ,
342- consts .DESCRIPTIONS .get (pdu .status , 'Unknown status' )),
343- int (pdu .status ),
344- )
351+ self .error_pdu_handler (pdu )
345352
346353 if pdu .command == 'unbind' : # unbind_res
347354 self .logger .info ('Unbind command received' )
0 commit comments