From 5fed18f60cec4bca35194403d1d6e429421e2417 Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Sat, 11 Jun 2022 17:52:10 +0530 Subject: [PATCH] Fix for exception in ratings API --- .../ratings/service/RatingServiceImpl.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java b/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java index eabe0dc39..2b4cd81c0 100644 --- a/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java +++ b/src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java @@ -21,7 +21,6 @@ import org.sunbird.ratings.responsecode.ResponseMessage; import java.sql.Timestamp; -import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Pattern; @@ -93,6 +92,7 @@ public SBApiResponse getRatings(String activityId, String activityType, String u } } catch (Exception e) { logger.error(e); + processExceptionBody(response, e, "", HttpStatus.INTERNAL_SERVER_ERROR); } return response; } @@ -177,6 +177,7 @@ public SBApiResponse getRatingSummary(String activityId, String activityType) { } } catch (Exception e) { logger.error(e); + processExceptionBody(response, e, "", HttpStatus.INTERNAL_SERVER_ERROR); } return response; } @@ -245,14 +246,14 @@ public SBApiResponse upsertRating(RequestRating requestRating) { kafkaProducer.push(updateRatingTopicName, ratingMessage); } catch (ValidationException ex) { logger.error(ex); - return processExceptionBody(response, ex, "", HttpStatus.BAD_REQUEST); + processExceptionBody(response, ex, "", HttpStatus.BAD_REQUEST); } catch (KafkaException ex) { logger.error(ex); - return processExceptionBody(response, ex, Constants.KAFKA_RATING_EXCEPTION_MESSAGE, HttpStatus.BAD_REQUEST); + processExceptionBody(response, ex, Constants.KAFKA_RATING_EXCEPTION_MESSAGE, HttpStatus.BAD_REQUEST); } catch (Exception ex) { logger.error(ex); String errMsg = Constants.RATING_GENERIC_EXCEPTION_MESSAGE; - return processExceptionBody(response, ex, errMsg, HttpStatus.INTERNAL_SERVER_ERROR); + processExceptionBody(response, ex, errMsg, HttpStatus.INTERNAL_SERVER_ERROR); } return response; @@ -336,9 +337,10 @@ public SBApiResponse ratingLookUp(LookupRequest lookupRequest) { } } catch (ValidationException ex) { logger.error(ex); - return processExceptionBody(response, ex, "", HttpStatus.BAD_REQUEST); + processExceptionBody(response, ex, "", HttpStatus.BAD_REQUEST); } catch (Exception e) { logger.error(e); + processExceptionBody(response, e, "", HttpStatus.INTERNAL_SERVER_ERROR); } return response; @@ -408,13 +410,12 @@ private void validateRatingsInfo(ValidationBody validationBody, String flag) thr } - public SBApiResponse processExceptionBody(SBApiResponse response, Exception ex, + public void processExceptionBody(SBApiResponse response, Exception ex, String exceptionMessage, HttpStatus status) { String errMsg = exceptionMessage + ex.getMessage(); logger.info("Exception: " + errMsg); response.getParams().setErrmsg(errMsg); response.setResponseCode(status); - return response; } }