Skip to content

Commit

Permalink
add more useful error messages for OpenShift
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed May 23, 2021
1 parent 42edb2e commit 7b497e5
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -8,16 +8,19 @@
import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -103,12 +106,18 @@ public String getToken(String apiServerURL, String caCertData, boolean skipTlsVe
if (token == null || System.currentTimeMillis() > token.expire) {
try {
token = refreshToken(apiServerURL, caCertData, skipTlsVerify);
} catch (ClientProtocolException e) {
throw new IOException("Can't parse protocol in the OAuth server URL ('" + apiServerURL + "')", e);
} catch (HttpClientWithTLSOptionsFactory.TLSConfigurationError e) {
throw new IOException("Could not configure SSL Factory in HttpClientWithTLSOptionsFactory: " + e.getMessage(), e);
} catch (URISyntaxException e) {
throw new IOException("The OAuth server URL was invalid ('" + apiServerURL + "'): " + e.getMessage(), e);
} catch (HttpHostConnectException e) {
throw new IOException("Can't connect to the OAuth server ('" + apiServerURL + "'): " + e.getMessage(), e);
} catch (TokenResponseError e) {
throw new IOException("The response from the OAuth server was invalid: " + e.getMessage(), e);
} catch (UnknownHostException e) {
throw new IOException("Can't resolve OAuth server hostname ('" + apiServerURL + "'): " + e.getMessage(), e);
} catch (URISyntaxException e) {
throw new IOException("The OAuth server URL was invalid ('" + apiServerURL + "'): " + e.getMessage(), e);
}

this.tokenCache.put(apiServerURL, token);
Expand Down

0 comments on commit 7b497e5

Please sign in to comment.