~hudson-openstack/glance/milestone-proposed

« back to all changes in this revision

Viewing changes to glance/common/exception.py

  • Committer: Tarmac
  • Author(s): Brian Waldon, Yuriy Taraday, Justin Shepherd, Ewan Mellor, Thierry Carrez
  • Date: 2011-06-28 19:42:20 UTC
  • mfrom: (139.9.1 d2-merge)
  • Revision ID: tarmac-20110628194220-rhxw4nwelxeolztc
Merge diablo-2 development work

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
    pass
84
84
 
85
85
 
 
86
class ClientConnectionError(Exception):
 
87
    """Error resulting from a client connecting to a server"""
 
88
    pass
 
89
 
 
90
 
86
91
def wrap_exception(f):
87
92
    def _wrap(*args, **kw):
88
93
        try:
96
101
            raise
97
102
    _wrap.func_name = f.func_name
98
103
    return _wrap
 
104
 
 
105
 
 
106
class GlanceException(Exception):
 
107
    """
 
108
    Base Glance Exception
 
109
 
 
110
    To correctly use this class, inherit from it and define
 
111
    a 'message' property. That message will get printf'd
 
112
    with the keyword arguments provided to the constructor.
 
113
    """
 
114
    message = "An unknown exception occurred"
 
115
 
 
116
    def __init__(self, **kwargs):
 
117
        try:
 
118
            self._error_string = self.message % kwargs
 
119
 
 
120
        except Exception:
 
121
            # at least get the core message out if something happened
 
122
            self._error_string = self.message
 
123
 
 
124
    def __str__(self):
 
125
        return self._error_string
 
126
 
 
127
 
 
128
class InvalidContentType(GlanceException):
 
129
    message = "Invalid content type %(content_type)s"