Skip to content

Commit 9e1bf62

Browse files
committed
fix: parsing unhandled exceptions
1 parent 3a19f5d commit 9e1bf62

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/main/java/io/github/isagroup/services/parsing/FeatureParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private static Automation parseMapToAutomation(String featureName, Map<String, O
134134

135135
try {
136136
automation.setAutomationType(AutomationType.valueOf(automationType));
137-
} catch (IllegalArgumentException e) {
137+
} catch (NullPointerException | IllegalArgumentException e) {
138138
throw new InvalidAutomationTypeException(
139139
"The feature " + featureName + " does not have a supported automationType (" + Arrays.toString(AutomationType.values()) + "). Current value: "
140140
+ automationType);
@@ -279,7 +279,7 @@ private static void parsePaymentValue(Feature feature, String featureName, Map<S
279279
for (String paymentType : allowedPaymentTypes) {
280280
try {
281281
PaymentType.valueOf(paymentType);
282-
} catch (IllegalArgumentException e) {
282+
} catch (NullPointerException | IllegalArgumentException e) {
283283
throw new InvalidDefaultValueException("The feature " + featureName
284284
+ " does not have a valid defaultValue consisting on a list of supported paymentType ("+Arrays.toString(PaymentType.values())+"). PaymentType that generates the issue: " + paymentType);
285285
}

src/main/java/io/github/isagroup/services/parsing/PlanParser.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,16 @@ private static void setUsageLimitsToPlan(String planName, Map<String, Object> ma
196196
} else {
197197
UsageLimit usageLimit = plan.getUsageLimits().get(planUsageLimitName);
198198

199-
Object value = planUsageLimitMap.get("value");
199+
Object value = null;
200+
try{
201+
value = planUsageLimitMap.get("value");
202+
}
203+
catch (NullPointerException e){
204+
throw new InvalidDefaultValueException("The usageLimit " + planUsageLimitName
205+
+ " does not have a valid value. Current valueType: "
206+
+ usageLimit.getValueType().toString() + "; Current value in plan " + plan.getName() + " is null");
207+
}
208+
200209
boolean isValueNull = (value == null);
201210

202211
if (isValueNull){
@@ -251,7 +260,7 @@ public static void parsePaymentValue(Feature feature, String featureName, Map<St
251260
for (String type : allowedPaymentTypes) {
252261
try {
253262
PaymentType.valueOf(type);
254-
} catch (IllegalArgumentException e) {
263+
} catch (NullPointerException | IllegalArgumentException e) {
255264
throw new InvalidDefaultValueException(
256265
"Invalid payment type for feature \"" + featureName + "\": \"" + type + "\" is not a supported payment type. "
257266
+ "Supported types are: " + Arrays.toString(PaymentType.values()) + ". "

src/main/java/io/github/isagroup/services/parsing/PricingManagerParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ private static void setPlans(Map<String, Object> map, PricingManager pricingMana
342342
}
343343

344344
private static void setAddOns(Map<String, Object> map, PricingManager pricingManager) {
345-
Map<String, Object> addOnsMap = (Map<String, Object>) map.get("addOns");
345+
Map<String, Object> addOnsMap = null;
346+
if (map.get("addOns") instanceof Map) {
347+
addOnsMap = (Map<String, Object>) map.get("addOns");
348+
}
346349

347350
if (addOnsMap == null) {
348351
return;
@@ -356,7 +359,7 @@ private static void setAddOns(Map<String, Object> map, PricingManager pricingMan
356359
AddOn addOn = AddOnParser.parseMapToAddOn(addOnName, addOnMap, pricingManager);
357360

358361
pricingManager.getAddOns().put(addOnName, addOn);
359-
} catch (ClassCastException e) {
362+
} catch (ClassCastException | NullPointerException | IllegalArgumentException e) {
360363
throw new PricingParsingException(
361364
"An error has occurred while parsing the add-on " + addOnName + ". Error: " + e.getMessage());
362365
}

src/main/java/io/github/isagroup/services/parsing/UsageLimitParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static UsageLimit parseMapToUsageLimit(String limitName, Map<String, Obje
4747
default:
4848
return null;
4949
}
50-
} catch (IllegalArgumentException e) {
50+
} catch (NullPointerException | IllegalArgumentException e) {
5151
throw new IllegalArgumentException("The usage limit " + limitName
5252
+ " does not have a supported type (" + Arrays.toString(UsageLimitType.values()) + "). Current type value: " + (String) limitMap.get("type"));
5353
}
@@ -96,7 +96,7 @@ private static void loadBasicAttributes(UsageLimit limit, String limitName, Map<
9696
limit.setDescription((String) map.get("description"));
9797
try {
9898
limit.setValueType(ValueType.valueOf((String) map.get("valueType")));
99-
} catch (IllegalArgumentException e) {
99+
} catch (NullPointerException | IllegalArgumentException e) {
100100
throw new InvalidValueTypeException("The feature " + limitName
101101
+ " does not have a supported valueType (" + Arrays.toString(ValueType.values()) + "). Current valueType: " + (String) map.get("valueType"));
102102
}

0 commit comments

Comments
 (0)