Comment 1 for bug 641266

Revision history for this message
Curtis Hovey (sinzui) wrote :

There are two assertions. I think we want to revise the code to explicitly raise an ValueError type because the status is not valid for the current state. We wrap the error in expose() so that the API user can see the message. This might be the way to do this.

lp.registry.errors:
from lazr.restful.declarations import webservice_error
class TeamMembershipTransitionError(ValueError):
    # HTTP Error: 'Not acceptable'
    webservice_error(406)

lp.registry.model.teammembership:
from lazr.restful.error import expose

        if self.status not in state_transition:
            raise expose(TeamMembershipTransitionError(
                "Unknown status: %s" % self.status.name))
        if status not in state_transition[self.status]:
            raise expose(TeamMembershipTransitionError(
                "Bad state transition from %s to %s"
                % (self.status.name, status.name))