Skip to content

fix: parsing unhandled exceptions #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static Automation parseMapToAutomation(String featureName, Map<String, O

try {
automation.setAutomationType(AutomationType.valueOf(automationType));
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new InvalidAutomationTypeException(
"The feature " + featureName + " does not have a supported automationType (" + Arrays.toString(AutomationType.values()) + "). Current value: "
+ automationType);
Expand Down Expand Up @@ -279,7 +279,7 @@ private static void parsePaymentValue(Feature feature, String featureName, Map<S
for (String paymentType : allowedPaymentTypes) {
try {
PaymentType.valueOf(paymentType);
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new InvalidDefaultValueException("The feature " + featureName
+ " does not have a valid defaultValue consisting on a list of supported paymentType ("+Arrays.toString(PaymentType.values())+"). PaymentType that generates the issue: " + paymentType);
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/io/github/isagroup/services/parsing/PlanParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,16 @@ private static void setUsageLimitsToPlan(String planName, Map<String, Object> ma
} else {
UsageLimit usageLimit = plan.getUsageLimits().get(planUsageLimitName);

Object value = planUsageLimitMap.get("value");
Object value = null;
try{
value = planUsageLimitMap.get("value");
}
catch (NullPointerException e){
throw new InvalidDefaultValueException("The usageLimit " + planUsageLimitName
+ " does not have a valid value. Current valueType: "
+ usageLimit.getValueType().toString() + "; Current value in plan " + plan.getName() + " is null");
}

boolean isValueNull = (value == null);

if (isValueNull){
Expand Down Expand Up @@ -251,7 +260,7 @@ public static void parsePaymentValue(Feature feature, String featureName, Map<St
for (String type : allowedPaymentTypes) {
try {
PaymentType.valueOf(type);
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new InvalidDefaultValueException(
"Invalid payment type for feature \"" + featureName + "\": \"" + type + "\" is not a supported payment type. "
+ "Supported types are: " + Arrays.toString(PaymentType.values()) + ". "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ private static void setPlans(Map<String, Object> map, PricingManager pricingMana
}

private static void setAddOns(Map<String, Object> map, PricingManager pricingManager) {
Map<String, Object> addOnsMap = (Map<String, Object>) map.get("addOns");
Map<String, Object> addOnsMap = null;
if (map.get("addOns") instanceof Map) {
addOnsMap = (Map<String, Object>) map.get("addOns");
}

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

pricingManager.getAddOns().put(addOnName, addOn);
} catch (ClassCastException e) {
} catch (ClassCastException | NullPointerException | IllegalArgumentException e) {
throw new PricingParsingException(
"An error has occurred while parsing the add-on " + addOnName + ". Error: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static UsageLimit parseMapToUsageLimit(String limitName, Map<String, Obje
default:
return null;
}
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new IllegalArgumentException("The usage limit " + limitName
+ " does not have a supported type (" + Arrays.toString(UsageLimitType.values()) + "). Current type value: " + (String) limitMap.get("type"));
}
Expand Down Expand Up @@ -96,7 +96,7 @@ private static void loadBasicAttributes(UsageLimit limit, String limitName, Map<
limit.setDescription((String) map.get("description"));
try {
limit.setValueType(ValueType.valueOf((String) map.get("valueType")));
} catch (IllegalArgumentException e) {
} catch (NullPointerException | IllegalArgumentException e) {
throw new InvalidValueTypeException("The feature " + limitName
+ " does not have a supported valueType (" + Arrays.toString(ValueType.values()) + "). Current valueType: " + (String) map.get("valueType"));
}
Expand Down