source: fedd/federation/service_error.py @ d75005b

Last change on this file since d75005b was e83f2f2, checked in by Ted Faber <faber@…>, 14 years ago

Move proofs around. Lots of changes, including fault handling.

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[ef36c1e]1#!/usr/local/bin/python
2
3# This is used to make the service error reporting independent of the
4# transport.  The XMLRPC and SOAP dispatchers will convert it into
5# transport-specific errors
6class service_error(RuntimeError):
7    access = 1
[058f58e]8    protocol= 2
[ef36c1e]9    req = 3
10    server_config = 4
11    internal = 5
[3441fe3]12    partial = 6
13    federant = 7
[9d3e646]14    connect = 8
[ef36c1e]15    code_str = { 
16        access : "Access Denied",
[058f58e]17        protocol : "Protocol Error",
[ef36c1e]18        req : "Badly Formed Request",
19        server_config: "Server Configuration Error",
[3441fe3]20        internal : "Internal Error",
[9d3e646]21        partial: "Partial Embedding",
22        federant: "Federant Error",
23        connect: "Connection Error",
[ef36c1e]24    }
25    str_code = dict([ (v, k) for k, v in code_str.iteritems() ])
[9d3e646]26    client_errors = ( req, partial)
27    server_errors = ( access, protocol, server_config, internal,
28            federant, connect)
[ef36c1e]29
[e83f2f2]30    def __init__(self, code=None, desc=None, from_string=None, proof=None):
[ef36c1e]31        self.code = code
32        self.desc = desc
[e83f2f2]33        self.proof = proof or []
34        if not isinstance (self.proof, list): self.proof = [ proof ]
[ef36c1e]35        if code == None:
36            self.set_code_from_string(from_string)
37        RuntimeError.__init__(self, desc)
38
39    def code_string(self, code=None):
40        code = code or self.code
41        return service_error.code_str.get(code)
42   
43    def set_code_from_string(self, errstr):
44        self.code = service_error.str_code.get(errstr, service_error.internal)
45        return self.code
46   
47    def is_client_error(self):
48        return self.code in service_error.client_errors
49
50    def is_server_error(self):
51        return self.code in service_error.server_errors
Note: See TracBrowser for help on using the repository browser.