source: fedd/federation/service_error.py @ 5018d82

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since 5018d82 was 9d3e646, checked in by Ted Faber <faber@…>, 16 years ago

Differentiate between a failure to connect to a service and the service being
provided using an unexpected protocol. Deal with the internal connection error
more cleanly when the connection is being made to an internal service. That
is, when an internal service is down, propagate a clean error out to the
caller. Before this change, the internal service failure would look like a
protocol error on the external service (SOAP being provided by XMLRPC, for
example) and try the other protocol, which would fail with a misleading error.

  • Property mode set to 100644
File size: 1.4 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
30    def __init__(self, code=None, desc=None, from_string=None):
31        self.code = code
32        self.desc = desc
33        if code == None:
34            self.set_code_from_string(from_string)
35        RuntimeError.__init__(self, desc)
36
37    def code_string(self, code=None):
38        code = code or self.code
39        return service_error.code_str.get(code)
40   
41    def set_code_from_string(self, errstr):
42        self.code = service_error.str_code.get(errstr, service_error.internal)
43        return self.code
44   
45    def is_client_error(self):
46        return self.code in service_error.client_errors
47
48    def is_server_error(self):
49        return self.code in service_error.server_errors
Note: See TracBrowser for help on using the repository browser.