From ed14eacb00f89f82774d8adba9906321701b232b Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 16 Jun 2011 11:16:12 +0200 Subject: [PATCH] NEXUS-4380: modified the exception handling to log only error conditions, if the exception to be handled is instance of ResourceException. --- ...actResourceStoreContentPlexusResource.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/nexus/nexus-rest-api/src/main/java/org/sonatype/nexus/rest/AbstractResourceStoreContentPlexusResource.java b/nexus/nexus-rest-api/src/main/java/org/sonatype/nexus/rest/AbstractResourceStoreContentPlexusResource.java index 8ae8d849b0..d7e5b58b6f 100644 --- a/nexus/nexus-rest-api/src/main/java/org/sonatype/nexus/rest/AbstractResourceStoreContentPlexusResource.java +++ b/nexus/nexus-rest-api/src/main/java/org/sonatype/nexus/rest/AbstractResourceStoreContentPlexusResource.java @@ -373,9 +373,7 @@ protected Object renderItem( Context context, Request req, Response res, Variant } else { - res.setStatus( Status.REDIRECTION_NOT_MODIFIED, "The resource is not modified!" ); - - return null; + throw new ResourceException( Status.REDIRECTION_NOT_MODIFIED, "Resource is not modified." ); } } else if ( req.getConditions().getNoneMatch() != null && req.getConditions().getNoneMatch().size() > 0 @@ -766,7 +764,7 @@ else if ( !o2.isLeaf() ) * * @param t */ - protected void handleException( Request req, Response res, Exception t ) + protected void handleException( final Request req, final Response res, final Exception t ) throws ResourceException { // just set this flag to true in any if-else branch you want to see @@ -835,6 +833,18 @@ else if ( t instanceof AccessDeniedException ) } finally { + if ( t instanceof ResourceException ) + { + ResourceException re = (ResourceException) t; + + if ( re.getStatus() != null && !re.getStatus().isError() ) + { + // do not spam the log with non-error responses, we need only errors to have logged in case when + // exception to be handled is ResourceException + return; + } + } + String message = "Got exception during processing request \"" + req.getMethod() + " " + req.getResourceRef().toString() + "\": "; @@ -887,7 +897,7 @@ else if ( t instanceof AccessDeniedException ) * @param res * @param t */ - public static void challengeIfNeeded( Request req, Response res, AccessDeniedException t ) + public static void challengeIfNeeded( final Request req, final Response res, final AccessDeniedException t ) { // TODO: a big fat problem here! // this makes restlet code tied to Servlet code, and we what is happening here is VERY dirty!