Protocol error handler fixes

- was broken if there was no error message in "raise"
- added default texts for network exceptions
This commit is contained in:
Peter Šurda 2017-12-29 08:49:08 +01:00
parent 02490e3286
commit e9b1aa48a9
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 18 additions and 10 deletions

View File

@ -8,23 +8,28 @@ from network.dandelion import Dandelion
import protocol
import state
class BMObjectInsufficientPOWError(Exception): pass
class BMObjectInsufficientPOWError(Exception):
errorCodes = ("Insufficient proof of work")
class BMObjectInvalidDataError(Exception): pass
class BMObjectInvalidDataError(Exception):
errorCodes = ("Data invalid")
class BMObjectExpiredError(Exception): pass
class BMObjectExpiredError(Exception):
errorCodes = ("Object expired")
class BMObjectUnwantedStreamError(Exception): pass
class BMObjectUnwantedStreamError(Exception):
errorCodes = ("Object in unwanted stream")
class BMObjectInvalidError(Exception): pass
class BMObjectInvalidError(Exception):
errorCodes = ("Invalid object")
class BMObjectAlreadyHaveError(Exception):
pass
errorCodes = ("Already have this object")
class BMObject(object):

View File

@ -24,13 +24,16 @@ import shared
import state
import protocol
class BMProtoError(ProxyError): pass
class BMProtoError(ProxyError):
errorCodes = ("Protocol error")
class BMProtoInsufficientDataError(BMProtoError): pass
class BMProtoInsufficientDataError(BMProtoError):
errorCodes = ("Insufficient data")
class BMProtoExcessiveDataError(BMProtoError): pass
class BMProtoExcessiveDataError(BMProtoError):
errorCodes = ("Too much data")
class BMProto(AdvancedDispatcher, ObjectTracker):

View File

@ -10,7 +10,7 @@ import state
class ProxyError(Exception):
errorCodes = ("UnknownError")
def __init__(self, code):
def __init__(self, code=-1):
self.code = code
try:
self.message = self.__class__.errorCodes[self.code]