From: Olivier Lamy Date: Tue, 10 Feb 2015 11:10:09 +0000 (+1100) Subject: fix exception mapping X-Git-Tag: archiva-2.2.0~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=29faf4ed88c9c4d16fc75a210105335a78177344;p=archiva.git fix exception mapping --- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/ArchivaRestServiceExceptionMapper.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/ArchivaRestServiceExceptionMapper.java index e5e98d21d..5a6660160 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/ArchivaRestServiceExceptionMapper.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/ArchivaRestServiceExceptionMapper.java @@ -45,13 +45,13 @@ public class ArchivaRestServiceExceptionMapper @Override public int getStatusCode() { - return Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); + return e.getHttpErrorCode(); } @Override public Response.Status.Family getFamily() { - return Response.Status.Family.SERVER_ERROR; + return Response.Status.Family.familyOf( e.getHttpErrorCode() ); } @Override @@ -59,7 +59,9 @@ public class ArchivaRestServiceExceptionMapper { return e.getMessage(); } - } ).build(); + } )// + .entity( restError ) // + .build(); return response; } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java index 51c1bff85..f745c043d 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java @@ -31,7 +31,9 @@ import org.apache.archiva.rest.api.services.RepositoriesService; import org.apache.commons.io.FileUtils; import org.junit.Test; +import javax.ws.rs.BadRequestException; import javax.ws.rs.ForbiddenException; +import javax.ws.rs.core.Response; import java.io.File; import java.util.List; @@ -105,7 +107,7 @@ public class RepositoriesServiceTest } } - @Test( expected = ForbiddenException.class ) + @Test( expected = BadRequestException.class ) public void deleteWithRepoNull() throws Exception { @@ -122,9 +124,10 @@ public class RepositoriesServiceTest repositoriesService.deleteArtifact( artifact ); } - catch ( ForbiddenException e ) + catch ( BadRequestException e ) { - assertEquals( "not http 400 status", 400, e.getResponse().getStatus() ); + assertEquals( "not http " + Response.Status.BAD_REQUEST.getStatusCode() + " status", + Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus() ); throw e; } }