Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more useful error messages for OpenShift #32

Merged
merged 1 commit into from
May 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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