mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15:44 +01:00
31 lines
900 B
Java
31 lines
900 B
Java
|
|
package sonia.scm.api.v2;
|
||
|
|
|
||
|
|
import sonia.scm.ScmConstraintViolationException;
|
||
|
|
import sonia.scm.api.v2.resources.ScmViolationExceptionToErrorDtoMapper;
|
||
|
|
|
||
|
|
import javax.inject.Inject;
|
||
|
|
import javax.ws.rs.core.MediaType;
|
||
|
|
import javax.ws.rs.core.Response;
|
||
|
|
import javax.ws.rs.ext.ExceptionMapper;
|
||
|
|
import javax.ws.rs.ext.Provider;
|
||
|
|
|
||
|
|
@Provider
|
||
|
|
public class ScmConstraintValidationExceptionMapper implements ExceptionMapper<ScmConstraintViolationException> {
|
||
|
|
|
||
|
|
private final ScmViolationExceptionToErrorDtoMapper mapper;
|
||
|
|
|
||
|
|
@Inject
|
||
|
|
public ScmConstraintValidationExceptionMapper(ScmViolationExceptionToErrorDtoMapper mapper) {
|
||
|
|
this.mapper = mapper;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public Response toResponse(ScmConstraintViolationException exception) {
|
||
|
|
return Response
|
||
|
|
.status(Response.Status.BAD_REQUEST)
|
||
|
|
.type(MediaType.APPLICATION_JSON_TYPE)
|
||
|
|
.entity(mapper.map(exception))
|
||
|
|
.build();
|
||
|
|
}
|
||
|
|
}
|