diff --git a/src/main/java/de/caritas/cob/uploadservice/api/ApiResponseEntityExceptionHandler.java b/src/main/java/de/caritas/cob/uploadservice/api/ApiResponseEntityExceptionHandler.java index 24cd9e9..96bed84 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/ApiResponseEntityExceptionHandler.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/ApiResponseEntityExceptionHandler.java @@ -1,5 +1,7 @@ package de.caritas.cob.uploadservice.api; +import static de.caritas.cob.uploadservice.api.exception.cutomheader.CustomHttpHeader.QUOTA_REACHED; + import de.caritas.cob.uploadservice.api.exception.InvalidFileTypeException; import de.caritas.cob.uploadservice.api.exception.KeycloakException; import de.caritas.cob.uploadservice.api.exception.httpresponses.InternalServerErrorException; @@ -218,9 +220,8 @@ public ResponseEntity handleInternal(final QuotaReachedException ex, final WebRequest request) { ex.executeLogging(); - HttpHeaders headers = new HttpHeaders(); - headers.add("Reason", "quota reached"); - return handleExceptionInternal(null, null, headers, HttpStatus.FORBIDDEN, request); + return handleExceptionInternal(null, null, QUOTA_REACHED.buildHeader(), HttpStatus.FORBIDDEN, + request); } } diff --git a/src/main/java/de/caritas/cob/uploadservice/api/exception/cutomheader/CustomHttpHeader.java b/src/main/java/de/caritas/cob/uploadservice/api/exception/cutomheader/CustomHttpHeader.java new file mode 100644 index 0000000..7509da0 --- /dev/null +++ b/src/main/java/de/caritas/cob/uploadservice/api/exception/cutomheader/CustomHttpHeader.java @@ -0,0 +1,28 @@ +package de.caritas.cob.uploadservice.api.exception.cutomheader; + +import lombok.AllArgsConstructor; +import org.springframework.http.HttpHeaders; + +/** + * Constants to build custom http headers. + */ +@AllArgsConstructor +public enum CustomHttpHeader { + + QUOTA_REACHED("X-Reason", "QUOTA_REACHED"); + + private final String headerName; + private final String headerValue; + + /** + * Builds the {@link HttpHeaders} for the custom values. + * + * @return the {@link HttpHeaders} instance + */ + public HttpHeaders buildHeader() { + HttpHeaders headers = new HttpHeaders(); + headers.add(headerName, headerValue); + return headers; + } + +} diff --git a/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTestIT.java b/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTestIT.java index 220513b..9415569 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTestIT.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTestIT.java @@ -292,7 +292,7 @@ public void uploadFileToRoom_Should_ReturnForbiddenWithCustomHeader_When_quotaLi .header(RC_TOKEN_HEADER_PARAMETER_NAME, RC_TOKEN) .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID)) .andExpect(status().isForbidden()) - .andExpect(header().string("Reason", "quota reached")); + .andExpect(header().string("X-Reason", "QUOTA_REACHED")); } private String convertObjectToJson(Object object) throws JsonProcessingException {