Create error response for already existing entities

This commit is contained in:
René Pfeuffer
2018-10-25 15:31:42 +02:00
parent d185743ef0
commit 6eb3c38655
58 changed files with 249 additions and 226 deletions

View File

@@ -1,6 +1,8 @@
package sonia.scm.api.rest;
import sonia.scm.AlreadyExistsException;
import sonia.scm.api.v2.resources.ErrorDto;
import sonia.scm.web.VndMediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -12,7 +14,8 @@ public class AlreadyExistsExceptionMapper implements ExceptionMapper<AlreadyExis
@Override
public Response toResponse(AlreadyExistsException exception) {
return Response.status(Status.CONFLICT)
.entity(exception.getMessage())
.entity(ErrorDto.from(exception))
.type(VndMediaType.ERROR_TYPE)
.build();
}
}

View File

@@ -44,8 +44,6 @@ import org.apache.shiro.authc.credential.PasswordService;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ConcurrentModificationException;
import sonia.scm.NotFoundException;
import sonia.scm.api.rest.RestActionResult;
import sonia.scm.security.Role;
import sonia.scm.security.ScmSecurityException;

View File

@@ -45,7 +45,6 @@ import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.AlreadyExistsException;
import sonia.scm.NotFoundException;
import sonia.scm.NotSupportedFeatuerException;
import sonia.scm.Type;
@@ -516,13 +515,6 @@ public class RepositoryImportResource
// repository = new Repository(null, type, name);
manager.create(repository);
}
catch (AlreadyExistsException ex)
{
logger.warn("a {} repository with the name {} already exists", type,
name);
throw new WebApplicationException(Response.Status.CONFLICT);
}
catch (InternalRepositoryException ex)
{
handleGenericCreationFailure(ex, type, name);