private Map<String,String> checkForErrorsAndReturnResponse(HttpsURLConnection connection){
  try {
    if (connection.getResponseCode() >= SC_MULTIPLE_CHOICES) {
      String message;
      if (connection.getErrorStream() != null) {
        message=readResponse(connection.getErrorStream());
      }
 else {
        message="";
      }
      if (message.contains(HTML_TAG)) {
        message=message.substring(message.indexOf(BODY_OPENING_TAG) + 6,message.indexOf(BODY_CLOSING_TAG));
      }
      throw new MCApiRuntimeException(message,connection.getResponseCode());
    }
 else {
      Map<String,String> responseMap=new HashMap<String,String>();
      responseMap.put(MESSAGE,readResponse(connection.getInputStream()));
      responseMap.put(HTTP_CODE,String.valueOf(connection.getResponseCode()));
      return responseMap;
    }
  }
 catch (  IOException e) {
    throw new MCApiRuntimeException(readResponse(connection.getErrorStream()));
  }
}

private Map < String , String > checkForErrorsAndReturnResponse ( HttpsURLConnection connection ) { try { if ( connection . getResponseCode ( ) >= SC_MULTIPLE_CHOICES ) { String message ; if ( connection . getErrorStream ( ) != null ) { message = readResponse ( connection . getErrorStream ( ) ) ; } else { message = "" ; } if ( message . contains ( HTML_TAG ) ) { message = message . substring ( message . indexOf ( BODY_OPENING_TAG ) + 6 , message . indexOf ( BODY_CLOSING_TAG ) ) ; } throw new MCApiRuntimeException ( message , connection . getResponseCode ( ) ) ; } else { Map < String , String > responseMap = new HashMap < String , String > ( ) ; responseMap . put ( MESSAGE , readResponse ( connection . getInputStream ( ) ) ) ; responseMap . put ( HTTP_CODE , String . valueOf ( connection . getResponseCode ( ) ) ) ; return responseMap ; } } catch ( IOException e ) { throw new MCApiRuntimeException ( readResponse ( connection . getErrorStream ( ) ) ) ; } }
method to check the connection response for errors . returns the response if the response code is less than 300 . throws mcopenapiruntimeexception is connection errors .
