Skip to content

Commit

Permalink
Fix for exception in ratings API
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Jun 11, 2022
1 parent 2b79053 commit 5fed18f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/org/sunbird/ratings/service/RatingServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

}

0 comments on commit 5fed18f

Please sign in to comment.