Skip to content

Commit

Permalink
Merged changes from cbrelease-4.8.13
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Jun 4, 2024
2 parents c629082 + a37ec55 commit 8edda04
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,9 @@ public class Constants {
public static final String PAGE_ID = "pageId";
public static final String USERS_LIST = "userList";
public static final String TOTAL_COUNT = "totalCount";
public static final String TOO_MANY_REQUESTS = "TOO_MANY_REQUESTS";
public static final String SERVER_ERROR = "serverError";
public static final String RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND";
public static final String MICROSITE_TOP_CONTENT_API = "api.microsite.top.content";
public static final String ICON = "icon";
public static final String DOMICILE_MEDIUM = "domicileMedium";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ public SBApiResponse generateOTP(Map<String, Object> otpRequests) {
headers.put(Constants.CONTENT_TYPE, Constants.APPLICATION_JSON);
Map<String, Object> apiResponse = outboundRequestHandlerService.fetchResultUsingPost(url, otpRequests,
headers);
if (Constants.OK.equalsIgnoreCase((String) apiResponse.get(Constants.RESPONSE_CODE))) {
String responseCode = (String) apiResponse.get(Constants.RESPONSE_CODE);
if (Constants.OK.equalsIgnoreCase(responseCode)) {
LOGGER.info("OTP Generation successful");
response.setVer("v1");
response.getParams().setStatus(Constants.SUCCESS.toUpperCase());
Expand All @@ -213,7 +214,26 @@ public SBApiResponse generateOTP(Map<String, Object> otpRequests) {
response.setResult(new HashMap<>());
response.getResult().put(Constants.RESPONSE, Constants.SUCCESS.toUpperCase());
} else {
errMsg = (String) ((Map<String, Object>)apiResponse.get(Constants.PARAMS)).get(Constants.ERROR_MESSAGE);
errMsg = (String) ((Map<String, Object>) apiResponse.get(Constants.PARAMS)).get(Constants.ERROR_MESSAGE);
response.getParams().setStatus(Constants.FAILED);

switch (responseCode.toUpperCase()) {
case Constants.TOO_MANY_REQUESTS:
response.setResponseCode(HttpStatus.TOO_MANY_REQUESTS);
break;
case Constants.CLIENT_ERROR:
response.setResponseCode(HttpStatus.BAD_REQUEST);
break;
case Constants.SERVER_ERROR:
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
break;
case Constants.RESOURCE_NOT_FOUND:
response.setResponseCode(HttpStatus.NOT_FOUND);
break;
default:
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
break;
}
}
} catch (Exception e) {
LOGGER.error(String.format("Exception in %s : %s", "generateOTP", e.getMessage()), e);
Expand All @@ -222,9 +242,7 @@ public SBApiResponse generateOTP(Map<String, Object> otpRequests) {
}
if (StringUtils.isNotBlank(errMsg)) {
LOGGER.error("OTP generation request failed, error message : ",errMsg);
response.getParams().setStatus(Constants.FAILED);
response.getParams().setErrmsg(errMsg);
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
}
return response;
}
Expand Down

0 comments on commit 8edda04

Please sign in to comment.