From a5445c016180c5987b26db40eb854bb33db9d843 Mon Sep 17 00:00:00 2001 From: Ruslan Forostianov Date: Wed, 26 Jun 2024 17:27:39 +0200 Subject: [PATCH] Throw IllegalStateException is downstream server return unsuccessful result --- .../web/PublicVirtualStudiesController.java | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/cbioportal/web/PublicVirtualStudiesController.java b/src/main/java/org/cbioportal/web/PublicVirtualStudiesController.java index f7d0eff1195..cc7a817f499 100644 --- a/src/main/java/org/cbioportal/web/PublicVirtualStudiesController.java +++ b/src/main/java/org/cbioportal/web/PublicVirtualStudiesController.java @@ -136,17 +136,11 @@ public ResponseEntity publishVirtualStudy( ResponseEntity 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); } @@ -172,17 +166,11 @@ public ResponseEntity retractVirtualStudy( ResponseEntity 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());