core, bridge: better GenericException handling

This commit is contained in:
Goffi 2013-12-17 00:56:39 +01:00
commit b6aaecc5c2
6 changed files with 33 additions and 11 deletions

View file

@ -77,11 +77,11 @@ class ProfileManager(urwid.WidgetWrap):
def _profileCreationFailure(self, reason):
self.host.removePopUp()
if reason=="CONFLICT":
if reason=="ConflictError":
message=_("A profile with this name already exists")
elif reason=="CANCELED":
elif reason=="CancelError":
message=_("Profile creation cancelled by backend")
elif reason=="DATABASE":
elif reason=="DATABASE": # FIXME: doesn't seem to exist !
message=_("Database error")
else:
message=_("Unknown reason (%s)") % reason

View file

@ -56,8 +56,13 @@ class DeferredNotAsync(dbus.DBusException):
class GenericException(dbus.DBusException):
def __init__(self, twisted_error):
super(GenericException, self).__init__()
mess = twisted_error.getErrorMessage()
self._dbus_error_name = const_ERROR_PREFIX + "." + (mess or str(twisted_error.__class__))
try:
error_name = str(twisted_error.value().__class__.__name__)
# twisted_error.value is a class
except TypeError:
# twisted_error.value is an instance
error_name = str(twisted_error.value.__class__.__name__)
self._dbus_error_name = const_ERROR_PREFIX + "." + error_name
class DbusObject(dbus.service.Object):

View file

@ -56,8 +56,13 @@ class DeferredNotAsync(dbus.DBusException):
class GenericException(dbus.DBusException):
def __init__(self, twisted_error):
super(GenericException, self).__init__()
mess = twisted_error.getErrorMessage()
self._dbus_error_name = const_ERROR_PREFIX + "." + (mess or str(twisted_error.__class__))
try:
error_name = str(twisted_error.value().__class__.__name__)
# twisted_error.value is a class
except TypeError:
# twisted_error.value is an instance
error_name = str(twisted_error.value.__class__.__name__)
self._dbus_error_name = const_ERROR_PREFIX + "." + error_name
class DbusObject(dbus.service.Object):

View file

@ -57,6 +57,18 @@ class DataError(Exception):
pass
class ConflictError(Exception):
pass
class CancelError(Exception):
pass
class InternalError(Exception):
pass
class BridgeInitError(Exception):
pass

View file

@ -164,9 +164,9 @@ class Params(object):
"""
if self.storage.hasProfile(profile):
info(_('The profile name already exists'))
return defer.fail(Failure(u"CONFLICT"))
return defer.fail(Failure(exceptions.ConflictError))
if not self.host.trigger.point("ProfileCreation", profile):
return defer.fail(Failure(u"CANCEL"))
return defer.fail(Failure(exceptions.CancelError))
return self.storage.createProfile(profile)
def deleteProfile(self, profile):

View file

@ -79,7 +79,7 @@ class ProsodyRegisterProtocol(protocol.ProcessProtocol):
self.deferred.callback(None)
else:
error(_(u"Can't register Prosody account (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data})
self.deferred.errback(Failure(u"INTERNAL"))
self.deferred.errback(Failure(exceptions.InternalError))
class MiscAccount(object):
@ -118,7 +118,7 @@ class MiscAccount(object):
raise exceptions.DataError
if profile.lower() in self.getConfig('reserved_list'):
return defer.fail(Failure(u'CONFLICT'))
return defer.fail(Failure(exceptions.ConflictError))
d = self.host.memory.asyncCreateProfile(profile)
d.addCallback(self._profileRegistered, email, password, profile)