Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* Business error codes emitted by the explore service.
*/
public enum ExploreBusinessErrorCode implements BusinessErrorCode {
EXPLORE_MAX_ELEMENTS_EXCEEDED("explore.maxElementsExceeded"),
EXPLORE_INCORRECT_CASE_FILE("explore.incorrectCaseFile");
EXPLORE_MAX_ELEMENTS_EXCEEDED("explore.maxElementsExceeded");

private final String code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ protected ExploreBusinessErrorCode getBusinessCode(ExploreException ex) {
protected HttpStatus mapStatus(ExploreBusinessErrorCode errorCode) {
return switch (errorCode) {
case EXPLORE_MAX_ELEMENTS_EXCEEDED -> HttpStatus.FORBIDDEN;
case EXPLORE_INCORRECT_CASE_FILE -> HttpStatus.UNPROCESSABLE_ENTITY;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@

package org.gridsuite.explore.server.services;

import org.gridsuite.explore.server.error.ExploreBusinessErrorCode;
import org.gridsuite.explore.server.error.ExploreException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriComponentsBuilder;
Expand Down Expand Up @@ -55,15 +52,8 @@ UUID importCase(MultipartFile multipartFile) {
}
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(
body, headers);
try {
caseUuid = restTemplate.postForObject(caseServerBaseUri + "/" + CASE_SERVER_API_VERSION + "/cases", request,
UUID.class);
} catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.UNPROCESSABLE_ENTITY) {
throw ExploreException.of(ExploreBusinessErrorCode.EXPLORE_INCORRECT_CASE_FILE, e.getMessage());
}
throw e;
}
caseUuid = restTemplate.postForObject(caseServerBaseUri + "/" + CASE_SERVER_API_VERSION + "/cases", request,
UUID.class);
return caseUuid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class ExploreExceptionTest {

@Test
void staticFactoryFormatsMessage() {
ExploreException exception = ExploreException.of(ExploreBusinessErrorCode.EXPLORE_INCORRECT_CASE_FILE,
ExploreException exception = ExploreException.of(ExploreBusinessErrorCode.EXPLORE_MAX_ELEMENTS_EXCEEDED,
"Case %s failed", "demo");

assertThat(exception.getMessage()).isEqualTo("Case demo failed");
assertThat(exception.getBusinessErrorCode()).isEqualTo(ExploreBusinessErrorCode.EXPLORE_INCORRECT_CASE_FILE);
assertThat(exception.getBusinessErrorCode()).isEqualTo(ExploreBusinessErrorCode.EXPLORE_MAX_ELEMENTS_EXCEEDED);
}

}