22import json
33import os
44import re
5+ import wmconstants
56
67
78def set_default_logging (parent_dir , level = logging .INFO ):
@@ -39,18 +40,17 @@ def get_error_log_file(action_type, object_type, parent_dir):
3940def _get_log_dir (parent_dir ):
4041 return parent_dir + "/app_logs"
4142
42- default_ignore_error_list = [
43- 'RESOURCE_ALREADY_EXISTS'
44- ]
45-
4643
4744def log_response_error (error_logger ,
48- response ,
49- error_msg = None ,
50- ignore_error_list = default_ignore_error_list ):
45+ response ,
46+ error_msg = None ,
47+ ignore_error_list = None ):
5148 """
5249 Logs errors based on the response. Usually used when the response is the http response.
5350 """
51+ if ignore_error_list is None :
52+ ignore_error_list = wmconstants .IGNORE_ERROR_LIST
53+
5454 if check_error (response , ignore_error_list ):
5555 if error_msg :
5656 error_logger .error (error_msg )
@@ -61,10 +61,14 @@ def log_response_error(error_logger,
6161 return False
6262
6363
64- def check_error (response , ignore_error_list = default_ignore_error_list ):
64+ def check_error (response , ignore_error_list = None ):
65+ if ignore_error_list is None :
66+ ignore_error_list = wmconstants .IGNORE_ERROR_LIST
67+
6568 if type (response ) is list :
6669 for resp in response :
67- if (_check_error_helper (resp , ignore_error_list )): return True
70+ if _check_error_helper (resp , ignore_error_list ):
71+ return True
6872 return False
6973 else :
7074 return _check_error_helper (response , ignore_error_list )
@@ -75,11 +79,6 @@ def _check_error_helper(response, ignore_error_list):
7579 if re .match ("Cluster .*? is in unexpected state (Running|Pending)\\ ." , response .get ("message" , "" )):
7680 return False
7781
78- # suppress principal error; this should be surfaced from the client level
79- if re .match ("Principal: .*? does not exist" , response .get ("message" , "" )) \
80- and (response .get ("error_code" ) == "RESOURCE_DOES_NOT_EXIST" ):
81- return False
82-
8382 return ('error_code' in response and response ['error_code' ] not in ignore_error_list ) \
8483 or ('error' in response and response ['error' ] not in ignore_error_list ) \
8584 or (response .get ('resultType' , None ) == 'error' and 'already exists' not in response .get ('summary' , None ))
0 commit comments