private BeanstreamApiException handleException(Exception ex, HttpsURLConnection connection) {
        String message = "";
        if (connection != null) {
            try {
                int responseCode = connection.getResponseCode();
                message = responseCode+" "+connection.getContent().toString();
            } catch (IOException ex1) {
                Logger.getLogger(HttpsConnector.class.getName()).log(Level.SEVERE, "Error getting response code", ex1);
            }
        } else {
            message = "Connection error";
        }
        return new BeanstreamApiException(ex, message);
    }