code: public static JSONObject processBadRespStr(int responseCode, String responseMsg) throws JSONException {
  
          JSONObject response = new JSONObject();
          response.put("responseCode", responseCode);
          if (responseMsg.equalsIgnoreCase("")) { // good response is empty string
              response.put("responseMsg", "");
          } else { // bad response is json string
              JSONObject errorObject = new JSONObject(responseMsg).optJSONObject("odata.error");
  
              String errorCode = errorObject.optString("code");
              String errorMsg = errorObject.optJSONObject("message").optString("value");
              response.put("responseCode", responseCode);
              response.put("errorCode", errorCode);
              response.put("errorMsg", errorMsg);
          }
  
          return response;
      }
docs: for good response
  
  @param responseCode
  @param responseMsg
  @return
  @throws JSONException