3232from awscli .arguments import BooleanArgument
3333from awscli .arguments import CLIArgument
3434from awscli .arguments import UnknownArgumentError
35- from awscli .arguments import BadArgumentError
3635
3736
3837LOG = logging .getLogger ('awscli.clidriver' )
@@ -472,7 +471,14 @@ def _create_operation_parser(self, arg_table):
472471
473472
474473class CLIOperationCaller (object ):
475- """Call an AWS operation and format the response."""
474+ """
475+ Call an AWS operation and format the response.
476+
477+ This class handles the non-error path. If an HTTP error occurs
478+ on the call to the service operation, it will be detected and
479+ handled by the :class:`awscli.errorhandler.ErrorHandler` which
480+ is registered on the ``after-call`` event.
481+ """
476482
477483 def __init__ (self , session ):
478484 self ._session = session
@@ -492,7 +498,6 @@ def invoke(self, operation_object, parameters, parsed_globals):
492498 ** parameters )
493499 self ._display_response (operation_object , response_data ,
494500 parsed_globals )
495- return self ._handle_http_response (http_response , response_data )
496501
497502 def _display_response (self , operation , response , args ):
498503 output = args .output
@@ -501,33 +506,3 @@ def _display_response(self, operation, response, args):
501506 formatter = get_formatter (output , args )
502507 formatter (operation , response )
503508
504- def _handle_http_response (self , http_response , response_data ):
505- if http_response .status_code >= 500 :
506- msg = self ._session .get_data ('messages/ServerError' )
507- code , message = self ._get_error_code_and_message (response_data )
508- sys .stderr .write (msg .format (error_code = code ,
509- error_message = message ))
510- sys .stderr .write ('\n ' )
511- return http_response .status_code - 399
512- if http_response .status_code >= 400 :
513- msg = self ._session .get_data ('messages/ClientError' )
514- code , message = self ._get_error_code_and_message (response_data )
515- sys .stderr .write (msg .format (error_code = code ,
516- error_message = message ))
517- sys .stderr .write ('\n ' )
518- return http_response .status_code - 399
519- return 0
520-
521- def _get_error_code_and_message (self , response ):
522- code = 'Unknown'
523- message = 'Unknown'
524- if 'Errors' in response :
525- if isinstance (response ['Errors' ], list ):
526- error = response ['Errors' ][- 1 ]
527- if 'Code' in error :
528- code = error ['Code' ]
529- elif 'Type' in error :
530- code = error ['Type' ]
531- if 'Message' in error :
532- message = error ['Message' ]
533- return (code , message )
0 commit comments