cleaning up some exceptions

This commit is contained in:
enus.linden
2008-10-01 07:37:34 +00:00
committed by Salad Dais
parent fbfd119550
commit 9b2d132005
3 changed files with 20 additions and 7 deletions

View File

@@ -93,16 +93,16 @@ class Capability(object):
headers = {"Content-type" : content_type}
headers.update(custom_headers) # give the user the ability to add headers
try:
restclient = getUtility(IRESTClient)
response = restclient.POST(self.public_url, serialized_payload, headers=headers)
except HTTPError, e:
if e.code==404:
raise exc.ResourceNotFound(self.public_url)
else:
raise exc.ResourceError(self.public_url, e.code, e.msg, e.fp.read(), method="POST")
if e.code==404:
raise exc.ResourceNotFound(self.public_url)
else:
raise exc.ResourceError(self.public_url, e.code, e.msg, e.fp.read(), method="POST")
# now deserialize the data again, we ask for a utility with the content type
# as the name
content_type_charset = response.headers['Content-Type']

View File

@@ -29,6 +29,7 @@ import grokcore.component as grok
from interfaces import IPlainPasswordCredential, IMD5PasswordCredential
from interfaces import ISerialization, ICredentialDeserialization
import exc
class PlainPasswordCredential(object):
"""a plain password credential"""
@@ -156,5 +157,5 @@ class CredentialLLSDDeserializer(grok.GlobalUtility):
return PlainPasswordCredential(payload['firstname'], payload['lastname'], payload['password'])
elif payload.has_key("md5-password"):
return MD5PasswordCredential(payload['firstname'], payload['lastname'], md5pw=payload['md5-password'])
raise Exception("couldn't deserialize credential payload '%s' because no matching format was found!" %str(payload))
raise exc.CredentialDeserializerNotFound(str(payload))

View File

@@ -88,6 +88,18 @@ class DeserializerNotFound(DeserializationError):
def __str__(self):
return "deserialization for %s not supported" %self.content_type
class CredentialDeserializerNotFound(DeserializationError):
"""raised if a deserializer for a certain content type couldn't be found
stores the content type inside a ``content_type`` attribute.
"""
def __init__(self, payload=''):
self.payload = payload
def __str__(self):
return "deserialization for payload '%s' not supported" % (self.payload)
class DeserializationFailed(DeserializationError):
"""raised if a deserializer couldn't deserialize a payload