Skip to content

Commit

Permalink
Proper error code handling in user patch API.
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Nov 21, 2022
1 parent 94ff851 commit 1dc4885
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -200,6 +201,9 @@ public Map<String, Object> fetchResultUsingPatch(String uri, Object request, Map
}
log.error("Error received: " + e.getResponseBodyAsString(), e);
}
if (response == null) {
return MapUtils.EMPTY_MAP;
}
return response;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,16 @@ public SBApiResponse profileUpdate(Map<String, Object> 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<String, Object>) updateResponse.get(Constants.PARAMS))
.get(Constants.ERROR_MESSAGE);
Expand Down

0 comments on commit 1dc4885

Please sign in to comment.