File: exceptions.py

package info (click to toggle)
python-bugzilla 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,072 kB
  • sloc: python: 5,760; makefile: 9
file content (38 lines) | stat: -rw-r--r-- 1,250 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.


class BugzillaError(Exception):
    """
    Error raised in the Bugzilla client code.
    """
    @staticmethod
    def get_bugzilla_error_string(exc):
        """
        Helper to return the bugzilla instance error message from an
        XMLRPC Fault, or any other exception type that's raised from bugzilla
        interaction
        """
        return getattr(exc, "faultString", str(exc))

    @staticmethod
    def get_bugzilla_error_code(exc):
        """
        Helper to return the bugzilla instance error code from an
        XMLRPC Fault, or any other exception type that's raised from bugzilla
        interaction
        """
        for propname in ["faultCode", "code"]:
            if hasattr(exc, propname):
                return getattr(exc, propname)
        return None

    def __init__(self, message, code=None):
        """
        :param code: The error code from the remote bugzilla instance. Only
            set if the error came directly from the remove bugzilla
        """
        self.code = code
        if self.code:
            message += " (code=%s)" % self.code
        Exception.__init__(self, message)