Skip to content

Commit

Permalink
Merge pull request #23 from CaritasDeutschland/feature-file-upload-re…
Browse files Browse the repository at this point in the history
…striction

feat: optimize quota reached header
  • Loading branch information
mebo4b authored Dec 2, 2020
2 parents 6bb0bf3 + 42d7337 commit ec3b6b3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -218,9 +220,8 @@ public ResponseEntity<Object> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ec3b6b3

Please sign in to comment.