Use mappers for errors

This commit is contained in:
René Pfeuffer
2018-10-26 14:20:19 +02:00
parent cd0964d850
commit 9279bfca5f
9 changed files with 151 additions and 90 deletions

View File

@@ -1,21 +1,13 @@
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;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@Provider
public class AlreadyExistsExceptionMapper implements ExceptionMapper<AlreadyExistsException> {
@Override
public Response toResponse(AlreadyExistsException exception) {
return Response.status(Status.CONFLICT)
.entity(ErrorDto.from(exception))
.type(VndMediaType.ERROR_TYPE)
.build();
public class AlreadyExistsExceptionMapper extends ContextualExceptionMapper<AlreadyExistsException> {
public AlreadyExistsExceptionMapper() {
super(AlreadyExistsException.class, Status.CONFLICT);
}
}