Skip to content

Commit

Permalink
Differentiate log levels between user and system exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
insyncoss committed May 10, 2023
1 parent 97f3ab1 commit 33cb4be
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void handleMetacatException(
final MetacatException e
) throws IOException {
final int status;
boolean logErrorLevel = false;
if (e instanceof MetacatAlreadyExistsException) {
status = HttpStatus.CONFLICT.value();
} else if (e instanceof MetacatBadRequestException) {
Expand All @@ -66,6 +67,7 @@ public void handleMetacatException(
} else if (e instanceof MetacatNotFoundException) {
status = HttpStatus.NOT_FOUND.value();
} else if (e instanceof MetacatNotSupportedException) {
logErrorLevel = true;
status = HttpStatus.NOT_IMPLEMENTED.value();
} else if (e instanceof MetacatUserMetadataException) {
// TODO: This makes no sense
Expand All @@ -75,9 +77,14 @@ public void handleMetacatException(
} else if (e instanceof MetacatUnAuthorizedException) {
status = HttpStatus.FORBIDDEN.value();
} else {
logErrorLevel = true;
status = HttpStatus.INTERNAL_SERVER_ERROR.value();
}
log.error(e.getLocalizedMessage(), e);
if (logErrorLevel) {
log.error(e.getLocalizedMessage(), e);
} else {
log.warn(e.getLocalizedMessage(), e);
}
response.sendError(status, e.getLocalizedMessage());
}

Expand Down

0 comments on commit 33cb4be

Please sign in to comment.