@@ -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,8 +326,24 @@ 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"""
339+
340+ if ignore_error_codes is not None :
341+ warnings .warn (
342+ "ignore_error_codes is deprecated, use set_error_pdu_handler to "
343+ "configure a custom error PDU handler instead." ,
344+ DeprecationWarning ,
345+ )
346+
327347 try :
328348 try :
329349 pdu = self .read_pdu ()
@@ -336,12 +356,7 @@ def read_once(self, ignore_error_codes=None, auto_send_enquire_link=True):
336356 return
337357
338358 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- )
359+ self .error_pdu_handler (pdu )
345360
346361 if pdu .command == 'unbind' : # unbind_res
347362 self .logger .info ('Unbind command received' )
0 commit comments