Skip to content

Commit

Permalink
Throw IllegalStateException is downstream server return unsuccessful …
Browse files Browse the repository at this point in the history
…result
  • Loading branch information
forus committed Jun 26, 2024
1 parent c27cf33 commit a5445c0
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,11 @@ public ResponseEntity<VirtualStudy> publishVirtualStudy(
ResponseEntity<VirtualStudy> responseEntity = getVirtualStudyById(id);
HttpStatusCode statusCode = responseEntity.getStatusCode();
VirtualStudy virtualStudy = responseEntity.getBody();
if (!statusCode.is2xxSuccessful()) {
if (!statusCode.is2xxSuccessful() || virtualStudy == null) {
LOG.error("The downstream server replied with statusCode={} and body={}." +
" Replying with the same status code to the client.",
statusCode, virtualStudy);
return new ResponseEntity<>(null, statusCode);
}
if (virtualStudy == null) {
LOG.error("The downstream server replied without body and statusCode={}." +
" Replying with internal server error status code to the client.",
statusCode);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
throw new IllegalStateException("The downstream server response is not successful");
}
return publishVirtualStudyData(virtualStudy.getData(), providedPublisherApiKey, typeOfCancerId, pmid);
}
Expand All @@ -172,17 +166,11 @@ public ResponseEntity retractVirtualStudy(
ResponseEntity<VirtualStudy> responseEntity = getVirtualStudyById(id);
HttpStatusCode statusCode = responseEntity.getStatusCode();
VirtualStudy virtualStudy = responseEntity.getBody();
if (!statusCode.is2xxSuccessful()) {
if (!statusCode.is2xxSuccessful() || virtualStudy == null) {
LOG.error("The downstream server replied with statusCode={} and body={}." +
" Replying with the same status code to the client.",
statusCode, virtualStudy);
return new ResponseEntity<>(null, statusCode);
}
if (virtualStudy == null) {
LOG.error("The downstream server replied without body and statusCode={}." +
" Replying with internal server error status code to the client.",
statusCode);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
throw new IllegalStateException("The downstream server response is not successful");
}
VirtualStudyData data = virtualStudy.getData();
data.setUsers(Collections.emptySet());
Expand Down

0 comments on commit a5445c0

Please sign in to comment.