diff --git a/src/main/java/de/caritas/cob/consultingtypeservice/api/ApiDefaultResponseEntityExceptionHandler.java b/src/main/java/de/caritas/cob/consultingtypeservice/api/ApiDefaultResponseEntityExceptionHandler.java index 40c9cccc..f75ea2c7 100644 --- a/src/main/java/de/caritas/cob/consultingtypeservice/api/ApiDefaultResponseEntityExceptionHandler.java +++ b/src/main/java/de/caritas/cob/consultingtypeservice/api/ApiDefaultResponseEntityExceptionHandler.java @@ -1,5 +1,6 @@ package de.caritas.cob.consultingtypeservice.api; +import de.caritas.cob.consultingtypeservice.api.exception.httpresponses.ConflictException; import de.caritas.cob.consultingtypeservice.api.service.LogService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,6 +32,13 @@ public ResponseEntity handleInternal( return new ResponseEntity<>(EMPTY_HEADERS, HttpStatus.INTERNAL_SERVER_ERROR); } + @ExceptionHandler({ConflictException.class}) + public ResponseEntity handleInternal( + final ConflictException ex, final WebRequest request) { + LogService.logInternalServerError(ex); + return new ResponseEntity<>(EMPTY_HEADERS, HttpStatus.CONFLICT); + } + @ExceptionHandler({AccessDeniedException.class}) public ResponseEntity handleInternal( final AccessDeniedException ex, final WebRequest request) { diff --git a/src/main/java/de/caritas/cob/consultingtypeservice/api/consultingtypes/ConsultingTypeMongoTenantAwareRepositoryService.java b/src/main/java/de/caritas/cob/consultingtypeservice/api/consultingtypes/ConsultingTypeMongoTenantAwareRepositoryService.java index 49edec65..1be35dd4 100644 --- a/src/main/java/de/caritas/cob/consultingtypeservice/api/consultingtypes/ConsultingTypeMongoTenantAwareRepositoryService.java +++ b/src/main/java/de/caritas/cob/consultingtypeservice/api/consultingtypes/ConsultingTypeMongoTenantAwareRepositoryService.java @@ -114,8 +114,8 @@ public Optional addConsultingType(final ConsultingType con || isConsultingTypeWithGivenSlugPresent(consultingType)) { LogService.logWarning( String.format( - "Could not add consulting type. id %s or slug %s is not unique", - consultingType.getId(), consultingType.getSlug())); + "Could not add consulting type. id %s or slug %s for tenant %s is not unique", + consultingType.getId(), consultingType.getSlug(), consultingType.getTenantId())); return Optional.empty(); } else { final ConsultingTypeEntity consultingTypeEntity = new ConsultingTypeEntity(); diff --git a/src/main/java/de/caritas/cob/consultingtypeservice/api/exception/httpresponses/ConflictException.java b/src/main/java/de/caritas/cob/consultingtypeservice/api/exception/httpresponses/ConflictException.java new file mode 100644 index 00000000..68c076fb --- /dev/null +++ b/src/main/java/de/caritas/cob/consultingtypeservice/api/exception/httpresponses/ConflictException.java @@ -0,0 +1,11 @@ +package de.caritas.cob.consultingtypeservice.api.exception.httpresponses; + +import de.caritas.cob.consultingtypeservice.api.service.LogService; + +/** Representation of a 409 - CONFLICT. */ +public class ConflictException extends CustomHttpStatusException { + + public ConflictException(String message) { + super(message, LogService::logWarning); + } +} diff --git a/src/main/java/de/caritas/cob/consultingtypeservice/api/service/ConsultingTypeService.java b/src/main/java/de/caritas/cob/consultingtypeservice/api/service/ConsultingTypeService.java index c735befe..c207043b 100644 --- a/src/main/java/de/caritas/cob/consultingtypeservice/api/service/ConsultingTypeService.java +++ b/src/main/java/de/caritas/cob/consultingtypeservice/api/service/ConsultingTypeService.java @@ -4,7 +4,7 @@ import de.caritas.cob.consultingtypeservice.api.auth.Authority.AuthorityValue; import de.caritas.cob.consultingtypeservice.api.consultingtypes.ConsultingTypeConverter; import de.caritas.cob.consultingtypeservice.api.consultingtypes.ConsultingTypeRepositoryService; -import de.caritas.cob.consultingtypeservice.api.exception.httpresponses.InternalServerErrorException; +import de.caritas.cob.consultingtypeservice.api.exception.httpresponses.ConflictException; import de.caritas.cob.consultingtypeservice.api.mapper.BasicConsultingTypeMapper; import de.caritas.cob.consultingtypeservice.api.mapper.ConsultingTypeMapper; import de.caritas.cob.consultingtypeservice.api.mapper.ExtendedConsultingTypeMapper; @@ -127,9 +127,10 @@ public FullConsultingTypeResponseDTO createConsultingType( return ConsultingTypeMapper.mapConsultingType( createdConsultingType.get(), FullConsultingTypeMapper::mapConsultingType); } else { - throw new InternalServerErrorException( + throw new ConflictException( String.format( - "Could not create a new consulting type with slug %s", consultingTypeDTO.getSlug())); + "Could not create a new consulting type with slug %s for tenant id %s", + consultingTypeDTO.getSlug(), consultingType.getTenantId())); } } diff --git a/src/main/java/de/caritas/cob/consultingtypeservice/filter/HttpTenantFilter.java b/src/main/java/de/caritas/cob/consultingtypeservice/filter/HttpTenantFilter.java index 01165edc..31b762a9 100644 --- a/src/main/java/de/caritas/cob/consultingtypeservice/filter/HttpTenantFilter.java +++ b/src/main/java/de/caritas/cob/consultingtypeservice/filter/HttpTenantFilter.java @@ -44,7 +44,7 @@ protected void doFilterInternal( filterChain.doFilter(request, response); TenantContext.clear(); } else { - log.info( + log.debug( "Skipping tenant filter for request: {} as it belongs to a tenancy whitelist.", request.getRequestURI()); filterChain.doFilter(request, response);