@@ -15,7 +15,8 @@ class FedexBaseServiceException(Exception):
1515 Serves as the base exception that other service-related exception objects
1616 are sub-classed from.
1717 """
18- def __init__ (self , value ):
18+ def __init__ (self , error_code , value ):
19+ self .error_code = error_code
1920 self .value = value
2021 def __str__ (self ):
2122 return repr (self .value )
@@ -25,8 +26,13 @@ class FedexFailure(FedexBaseServiceException):
2526 The request could not be handled at this time. This is generally a server
2627 problem.
2728 """
28- def __init__ (self ):
29- self .value = "Your request could not be handled at this time. This is likely Fedex server problems, try again later."
29+ pass
30+
31+ class FedexError (FedexBaseServiceException ):
32+ """
33+ These are generally problems with the client-provided data.
34+ """
35+ pass
3036
3137class FedexBaseService (object ):
3238 """
@@ -148,13 +154,31 @@ def __check_response_for_fedex_error(self):
148154 to any one WSDL.
149155 """
150156 if self .response .HighestSeverity == "FAILURE" :
151- raise FedexFailure ()
157+ for notification in self .response .Notifications :
158+ if notification .Severity == "FAILURE" :
159+ raise FedexFailure (notification .Code ,
160+ notification .Message )
161+
162+ def _check_response_for_request_errors (self ):
163+ """
164+ Override this in each service module to check for errors that are
165+ specific to that module. For example, invalid tracking numbers in
166+ a Tracking request.
167+ """
168+ pass
152169
153170 def send_request (self ):
154171 """
155172 Sends the assembled request on the child object.
156173 """
174+ # Send the request and get the response back.
157175 self .response = self ._assemble_and_send_request ()
176+ # Check the response for general Fedex errors/failures that aren't
177+ # specific to any given WSDL/request.
158178 self .__check_response_for_fedex_error ()
179+ # Check the response for errors specific to the particular request.
180+ # This is handled by an overridden method on the child object.
181+ self ._check_response_for_request_errors ()
182+ # Debug output.
159183 self .logger .info ("== FEDEX QUERY RESULT ==" )
160184 self .logger .info (self .response )
0 commit comments