Skip to content

Commit e6bc83b

Browse files
committed
Corrected exception handling for json deserializing steps
1 parent 472f1b6 commit e6bc83b

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

lib/net/authorize/util/ANetSensitiveFields.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ private static function fetchFromConfigFiles(){
1515
if(!class_exists(ANET_SENSITIVE_DATE_CONFIG_CLASS))
1616
exit("Class (".ANET_SENSITIVE_DATE_CONFIG_CLASS.") doesn't exist; can't deserialize json; can't log. Exiting.");
1717

18-
$serializer = SerializerBuilder::create()->build();
18+
$serializer = SerializerBuilder::create()->build();
1919

20-
$userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
20+
$userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
2121
$presentUserConfigFile = file_exists($userConfigFilePath);
22-
22+
2323
$configFilePath = dirname(__FILE__) . "/" . ANET_SENSITIVE_XMLTAGS_JSON_FILE;
2424
$useDefaultConfigFile = !$presentUserConfigFile;
25-
25+
2626
if ($presentUserConfigFile) { //client config for tags
2727
//read list of tags (and associated regex-patterns and replacements) from .json file
28-
$jsonFileData=file_get_contents($userConfigFilePath);
29-
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json');
30-
31-
$sensitiveTags = $sensitiveDataConfig->sensitiveTags;
32-
self::$sensitiveStringRegexes = $sensitiveDataConfig->sensitiveStringRegexes;
33-
34-
if (json_last_error() === JSON_ERROR_NONE) {// JSON is valid
28+
try{
29+
$jsonFileData=file_get_contents($userConfigFilePath);
30+
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json');
31+
32+
$sensitiveTags = $sensitiveDataConfig->sensitiveTags;
33+
self::$sensitiveStringRegexes = $sensitiveDataConfig->sensitiveStringRegexes;
3534
}
36-
else{
37-
echo "ERROR: Invalid json in: " . $userConfigFilePath . " json_last_error_msg : " . json_last_error_msg();
35+
36+
catch(Exception $e){
37+
echo "ERROR deserializing json from : " . $userConfigFilePath . "; Exception : " . $e->getMessage();
3838
$useDefaultConfigFile = true;
3939
}
4040
}
@@ -45,16 +45,16 @@ private static function fetchFromConfigFiles(){
4545
}
4646

4747
//read list of tags (and associated regex-patterns and replacements) from .json file
48+
try{
4849
$jsonFileData=file_get_contents($configFilePath);
4950
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json');
5051

5152
$sensitiveTags = $sensitiveDataConfig->sensitiveTags;
5253
self::$sensitiveStringRegexes = $sensitiveDataConfig->sensitiveStringRegexes;
53-
54-
if (json_last_error() === JSON_ERROR_NONE) {
5554
}
56-
else{
57-
exit("ERROR: Invalid json in: " . $configFilePath . " json_last_error_msg : " . json_last_error_msg());
55+
56+
catch(Exception $e){
57+
exit( "ERROR deserializing json from : " . $configFilePath . "; Exception : " . $e->getMessage());
5858
}
5959
}
6060

0 commit comments

Comments
 (0)