def get_exception_for_type_error(func, exc):
 message = str(exc)
 func_name = func.__name__
 invalid_num_args_pattern = ('%s\\(\\) takes %s \\d+ arguments? \\(\\d+ given\\)' % (func_name, '(exactly|at most|at least)'))
 unexpected_keyword_arg_pattern = ("%s\\(\\) got an unexpected keyword argument '(.*?)'" % func_name)
 if re.search(invalid_num_args_pattern, message):
  result = webob_exc.HTTPNotFound()
 elif re.search(unexpected_keyword_arg_pattern, message):
  match = re.match(unexpected_keyword_arg_pattern, message)
  if match:
   groups = match.groups()
   query_param_name = groups[0]
   msg = ('Unsupported query parameter: %s' % query_param_name)
  else:
   msg = 'Unknown error, please contact the administrator.'
  result = webob_exc.HTTPBadRequest(detail=msg)
 else:
  result = exc
 return result

def get_exception_for_type_error ( func , exc ) : message = str ( exc ) func_name = func . __name__ invalid_num_args_pattern = ( '%s\\(\\) takes %s \\d+ arguments? \\(\\d+ given\\)' % ( func_name , '(exactly|at most|at least)' ) ) unexpected_keyword_arg_pattern = ( "%s\\(\\) got an unexpected keyword argument '(.*?)'" % func_name ) if re . search ( invalid_num_args_pattern , message ) : result = webob_exc . HTTPNotFound ( ) elif re . search ( unexpected_keyword_arg_pattern , message ) : match = re . match ( unexpected_keyword_arg_pattern , message ) if match : groups = match . groups ( ) query_param_name = groups [ 0 ] msg = ( 'Unsupported query parameter: %s' % query_param_name ) else : msg = 'Unknown error, please contact the administrator.' result = webob_exc . HTTPBadRequest ( detail = msg ) else : result = exc return result
method which translates typeerror thrown by the controller method and intercepted inside jsexpose decorator and returns a better exception for it .