]> source.dussan.org Git - archiva.git/commitdiff
fix exception mapping
authorOlivier Lamy <olamy@apache.org>
Tue, 10 Feb 2015 11:10:09 +0000 (22:10 +1100)
committerOlivier Lamy <olamy@apache.org>
Tue, 10 Feb 2015 11:10:09 +0000 (22:10 +1100)
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/interceptors/ArchivaRestServiceExceptionMapper.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java

index e5e98d21db2581395897cd8a8621d142fbd48b46..5a6660160d03c8a556f20487cca72dabd57d2069 100644 (file)
@@ -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;
     }
index 51c1bff85f58489bd31f460a16450addf39fee8d..f745c043d73dc9e9db4915e67fbb3c8f4dd460cc 100644 (file)
@@ -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;
         }
     }