Skip to content

Commit

Permalink
review revisions. clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
tbradellis committed Oct 3, 2022
1 parent 8e39773 commit 338e527
Showing 1 changed file with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ public NewRelicApiImplementation() {
*/
@Override
public void noticeError(Throwable throwable, Map<String, ?> params) {
noticeError(throwable, params, throwable != null &&
isExpectedErrorConfigured(throwable.getClass().getName(), throwable.getMessage()),
false);
noticeError(throwable, params, isExpectedErrorConfigured(throwable), false);
}

/**
Expand All @@ -72,10 +70,7 @@ public void noticeError(Throwable throwable, Map<String, ?> params) {
@Override
public void noticeError(Throwable throwable) {
Map<String, String> params = Collections.emptyMap();
noticeError(throwable, params, throwable != null &&
isExpectedErrorConfigured(throwable.getClass().getName(),
throwable.getMessage()),
false);
noticeError(throwable, params, isExpectedErrorConfigured(throwable), false);

}

Expand Down Expand Up @@ -163,19 +158,23 @@ public void noticeError(String message, boolean expected) {
noticeError(message, params, expected);
}

private boolean isExpectedErrorConfigured(String expectedConfigName, String message) {
boolean expected = true;
String app_name = NewRelic.getAgent().getConfig().getValue("app_name");
Set<ExpectedErrorConfig> expectedErrors = ServiceFactory.getConfigService().getErrorCollectorConfig(app_name).getExpectedErrors();
for (ExpectedErrorConfig errorConfig : expectedErrors) {
if ((errorConfig.getErrorClass().equals(expectedConfigName) && errorConfig.getErrorMessage() == null) ||
(errorConfig.getErrorMessage() != null) &&
(errorConfig.getErrorClass().equals(expectedConfigName) && errorConfig.getErrorMessage().equals(message))) {
return expected;
private boolean isExpectedErrorConfigured(Throwable throwable) {
if (throwable != null) {
String expectedConfigName = throwable.getClass().getName();
String message = throwable.getMessage();
String app_name = NewRelic.getAgent().getConfig().getValue("app_name");
Set<ExpectedErrorConfig> expectedErrors = ServiceFactory.getConfigService().getErrorCollectorConfig(app_name).getExpectedErrors();
for (ExpectedErrorConfig errorConfig : expectedErrors) {
String errorClass = errorConfig.getErrorClass();
String errorMessage = errorConfig.getErrorMessage();
if ((errorClass.equals(expectedConfigName) && errorMessage == null) ||
(errorMessage != null) &&
(errorClass.equals(expectedConfigName) && errorMessage.equals(message))) {
return true;
}
}
}

return !expected;
return false;
}

private static Map<String, ?> filterErrorAtts(Map<String, ?> params, AttributeSender attributeSender) {
Expand Down

0 comments on commit 338e527

Please sign in to comment.