diff --git a/src/main/java/org/sunbird/common/service/OutboundRequestHandlerServiceImpl.java b/src/main/java/org/sunbird/common/service/OutboundRequestHandlerServiceImpl.java index 119304e3b..d8a67119e 100644 --- a/src/main/java/org/sunbird/common/service/OutboundRequestHandlerServiceImpl.java +++ b/src/main/java/org/sunbird/common/service/OutboundRequestHandlerServiceImpl.java @@ -3,6 +3,7 @@ import java.util.HashMap; import java.util.Map; +import org.apache.commons.collections.MapUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -200,6 +201,9 @@ public Map fetchResultUsingPatch(String uri, Object request, Map } log.error("Error received: " + e.getResponseBodyAsString(), e); } + if (response == null) { + return MapUtils.EMPTY_MAP; + } return response; } diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index 81f794262..5edb34963 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -531,6 +531,7 @@ public class Constants { public static final String NEW_COURSES = "newcourses"; public static final String OVERVIEW_BATCH_KEY = "/overview?batchId="; public static final String LEAF_NODES_COUNT = "leafNodesCount"; + public static final String CLIENT_ERROR = "CLIENT_ERROR"; private Constants() { throw new IllegalStateException("Utility class"); diff --git a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java index 2c24b86df..51915d269 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java +++ b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java @@ -150,12 +150,16 @@ public SBApiResponse profileUpdate(Map request, String userToken url.append(serverConfig.getSbUrl()).append(serverConfig.getLmsUserUpdatePath()); updateResponse = outboundRequestHandlerService.fetchResultUsingPatch( serverConfig.getSbUrl() + serverConfig.getLmsUserUpdatePath(), updateRequest, headerValues); - if (updateResponse.get(Constants.RESPONSE_CODE).equals(Constants.OK)) { + if (Constants.OK.equalsIgnoreCase((String) updateResponse.get(Constants.RESPONSE_CODE))) { response.setResponseCode(HttpStatus.OK); response.getResult().put(Constants.RESPONSE, Constants.SUCCESS); response.getParams().setStatus(Constants.SUCCESS); } else { - response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR); + if (Constants.CLIENT_ERROR.equalsIgnoreCase((String) updateResponse.get(Constants.RESPONSE_CODE))) { + response.setResponseCode(HttpStatus.BAD_REQUEST); + } else { + response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR); + } response.getParams().setStatus(Constants.FAILED); String errMsg = (String) ((Map) updateResponse.get(Constants.PARAMS)) .get(Constants.ERROR_MESSAGE);