| 1 |  |  | # -*- coding: utf-8 -*- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 | 1 |  | class Route4MeError(Exception): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 	""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	Base (abstract) error-class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 	""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 | 1 |  | 	def __init__( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 		self, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		message, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		code='route4me.sdk.other', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 		details=None, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 		inner=None, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 | 1 |  | 		super(Route4MeError, self).__init__(message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 		#: Unique error code. Helps to distinguish different errors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		#: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		#: :type: str | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 1 |  | 		self.code = code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 1 |  | 		if details is not None: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 1 |  | 			assert isinstance(details, dict) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		#: Some error details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		#: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		#: :type: dict | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 1 |  | 		self.details = details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		#: Internal exception that describes an original error. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		#: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		#: :type: Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 1 |  | 		self.inner = inner | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 1 |  | 	def get_message(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 1 |  | 		return super(Route4MeError, self).__str__() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 1 |  | 	def __str__(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 1 |  | 		s = '{tp}: [{code}] {message}'.format( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			tp=type(self).__name__, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			code=self.code, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			message=self.get_message(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  | 		return s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  | class Route4MeNetworkError(Route4MeError): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	Route4Me SDK network/connection errors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	Occurs on: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	- invalid SSL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	- network timeout | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	- wrong redirects (Route4Me API doesn't send redirect responses) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	- no connection, no path to route (DNS) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	More details could be observed using :py:attr:`~.Route4MeError.code` and | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	:py:attr:`~.Route4MeError.details` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  | 	pass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 1 |  | class Route4MeApiError(Route4MeError): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	Error on Route4Me SDK | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	.. todo:: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		Make this exception more detailed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  | 	""" | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 1 |  | 	def __init__( | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  | 		self, | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  | 		message, | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | 		code='route4me.sdk.other', | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 		details=None, | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 		inner=None, | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | 		method=None, | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 		url=None, | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 	): | 
            
                                                                        
                            
            
                                    
            
            
                | 83 | 1 |  | 		super(Route4MeApiError, self).__init__( | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 			message, | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 			code, | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 			details, | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 			inner | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 		) | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 90 | 1 |  | 		self.method = method | 
            
                                                                        
                            
            
                                    
            
            
                | 91 | 1 |  | 		self.url = url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 1 |  | class Route4MeValidationError(Route4MeError): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	Route4Me Validation error. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	Variable has invalid format/data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 1 |  | 	pass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 1 |  | class Route4MeEntityNotFoundError(Route4MeError): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	Requested entity was not found on Route4Me | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	""" | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 107 |  |  | 	pass | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |  |