Package restkit :: Module errors
[hide private]
[frames] | no frames]

Source Code for Module restkit.errors

 1  # -*- coding: utf-8 - 
 2  # 
 3  # This file is part of restkit released under the MIT license.  
 4  # See the NOTICE for more information. 
 5   
 6  """ 
 7  exception classes. 
 8  """ 
 9               
10 -class ResourceError(Exception):
11 """ default error class """
12 - def __init__(self, msg=None, http_code=None, response=None):
13 self.msg = msg or '' 14 self.status_int = http_code 15 self.response = response 16 Exception.__init__(self)
17
18 - def _get_message(self):
19 return self.msg
20 - def _set_message(self, msg):
21 self.msg = msg or ''
22 message = property(_get_message, _set_message) 23
24 - def __str__(self):
25 if self.msg: 26 return self.msg 27 try: 28 return str(self.__dict__) 29 except (NameError, ValueError, KeyError), e: 30 return 'Unprintable exception %s: %s' \ 31 % (self.__class__.__name__, str(e))
32 33
34 -class ResourceNotFound(ResourceError):
35 """Exception raised when no resource was found at the given url. 36 """
37
38 -class Unauthorized(ResourceError):
39 """Exception raised when an authorization is required to access to 40 the resource specified. 41 """
42
43 -class RequestFailed(ResourceError):
44 """Exception raised when an unexpected HTTP error is received in response 45 to a request. 46 47 48 The request failed, meaning the remote HTTP server returned a code 49 other than success, unauthorized, or NotFound. 50 51 The exception message attempts to extract the error 52 53 You can get the status code by e.http_code, or see anything about the 54 response via e.response. For example, the entire result body (which is 55 probably an HTML error page) is e.response.body. 56 """
57
58 -class RedirectLimit(Exception):
59 """Exception raised when the redirection limit is reached."""
60
61 -class RequestError(Exception):
62 """Exception raised when a request is malformed"""
63
64 -class InvalidUrl(Exception):
65 """ 66 Not a valid url for use with this software. 67 """
68
69 -class ResponseError(Exception):
70 """ Error raised while getting response or decompressing response stream"""
71 72
73 -class ProxyError(Exception):
74 """ raised when proxy error happend"""
75
76 -class BadStatusLine(Exception):
77 """ Exception returned by the parser when the status line is invalid""" 78 pass
79
80 -class ParserError(Exception):
81 """ Generic exception returned by the parser """ 82 pass
83