original_docstring:  Decorator that will wrap handler response in an API Gateway compatible dict with
      statusCode and json serialized body. If handler result has a 'body', this decorator
      will serialize it into the API Gateway body; if the handler result does _not_ have a
      body, this decorator will return statusCode 200 and serialize the entire result.
  
      Args:
          handler (func): a handler function with the signature (event, context) -> result
  
      Returns:
          handler (func): a lambda handler function that whose result is HTTPGateway compatible.
      
docstring: Decorator that will wrap handler response in an API Gateway compatible dict with
  statusCode and json serialized body. If handler result has a 'body', this decorator
  will serialize it into the API Gateway body; if the handler result does _not_ have a
  body, this decorator will return statusCode 200 and serialize the entire result.
docstring_tokens: Decorator that will wrap handler response in an API Gateway compatible dict with statusCode and json serialized body . If handler result has a ' body ' this decorator will serialize it into the API Gateway body ; if the handler result does _not_ have a body this decorator will return statusCode 200 and serialize the entire result .
code: def http_response(default_error_message=None):
      """ Decorator that will wrap handler response in an API Gateway compatible dict with
      statusCode and json serialized body. If handler result has a 'body', this decorator
      will serialize it into the API Gateway body; if the handler result does _not_ have a
      body, this decorator will return statusCode 200 and serialize the entire result.
  
      Args:
          handler (func): a handler function with the signature (event, context) -> result
  
      Returns:
          handler (func): a lambda handler function that whose result is HTTPGateway compatible.
      """
      def http_response_handler(handler):
          def handler_wrapper(event, context, **kwargs):
              try:
                  res = handler(event, context, **kwargs)
                  if not isinstance(res, dict):
                      raise Exception(f'Unsupported return type {type(res)}; response must be dict.')
                  return {
                      'headers': res.get('headers', {}),
                      'statusCode': res.get('statusCode', 200),
                      'body': json.dumps(res['body'], iterable_as_array=True) if 'body' in res else None,
                  }
              except HTTPResponseException as err:
                  return {
                      'statusCode': err.statusCode,
                      'body': json.dumps(err.body, iterable_as_array=True),
                  }
              except Exception as err:
                  # Try and handle HTTPResponseException like objects
                  if hasattr(err, 'statusCode') and hasattr(err, 'body'):
                      return {
                          'statusCode': err.statusCode,
                          'body': json.dumps(err.body, iterable_as_array=True),
                      }
                  else:
                      logger.exception(err)
                      lambda_function_name = context.function_name.split('.')[-1].replace('_', ' ')
                      return {
                          'statusCode': 500,
                          'body': default_error_message or f'Failed to {lambda_function_name}.',
                      }
  
          return handler_wrapper
      return http_response_handler
code_tokens: def http_response ( default_error_message = None ) : def http_response_handler ( handler ) : def handler_wrapper ( event , context , ** kwargs ) : try : res = handler ( event , context , ** kwargs ) if not isinstance ( res , dict ) : raise Exception ( f'Unsupported return type {type(res)}; response must be dict.' ) return { 'headers' : res . get ( 'headers' , { } ) , 'statusCode' : res . get ( 'statusCode' , 200 ) , 'body' : json . dumps ( res [ 'body' ] , iterable_as_array = True ) if 'body' in res else None , } except HTTPResponseException as err : return { 'statusCode' : err . statusCode , 'body' : json . dumps ( err . body , iterable_as_array = True ) , } except Exception as err : if hasattr ( err , 'statusCode' ) and hasattr ( err , 'body' ) : return { 'statusCode' : err . statusCode , 'body' : json . dumps ( err . body , iterable_as_array = True ) , } else : logger . exception ( err ) lambda_function_name = context . function_name . split ( '.' ) [ - 1 ] . replace ( '_' , ' ' ) return { 'statusCode' : 500 , 'body' : default_error_message or f'Failed to {lambda_function_name}.' , } return handler_wrapper return http_response_handler
short_docstring: Decorator that will wrap handler response in an API Gateway compatible dict with
  statusCode and json serialized body.
short_docstring_tokens: Decorator that will wrap handler response in an API Gateway compatible dict with statusCode and json serialized body .
comment: """ Decorator that will wrap handler response in an API Gateway compatible dict with
      statusCode and json serialized body. If handler result has a 'body', this decorator
      will serialize it into the API Gateway body; if the handler result does _not_ have a
      body, this decorator will return statusCode 200 and serialize the entire result.
  
      Args:
          handler (func): a handler function with the signature (event, context) -> result
  
      Returns:
          handler (func): a lambda handler function that whose result is HTTPGateway compatible.
      """$SEP$# Try and handle HTTPResponseException like objects