Skip to content

Commit ee80670

Browse files
hamaronTakashi Hamada
authored andcommitted
jenkinsci#39: Don't propagate IOException when GET for /CrumbIssuer fails.
1 parent 99d6f0e commit ee80670

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ public String get(String path) throws IOException {
164164
}
165165
}
166166

167+
/**
168+
* Perform a GET request and parse the response to the given class,
169+
* logging any IOException that is thrown rather than propagating it.
170+
*
171+
* @param path path to request, can be relative or absolute
172+
* @param cls class of the response
173+
* @param <T> type of the response
174+
* @return an instance of the supplied class
175+
*/
176+
public <T extends BaseModel> T getQuietly(String path, Class<T> cls) {
177+
T value;
178+
try {
179+
value = get(path, cls);
180+
return value;
181+
} catch (IOException e) {
182+
e.printStackTrace();
183+
return null;
184+
}
185+
}
186+
167187
/**
168188
* Perform a GET request and return the response as InputStream
169189
*
@@ -196,7 +216,7 @@ public <R extends BaseModel, D> R post(String path, D data, Class<R> cls) throws
196216
public <R extends BaseModel, D> R post(String path, D data, Class<R> cls, boolean crumbFlag) throws IOException {
197217
HttpPost request = new HttpPost(api(path));
198218
if (crumbFlag == true) {
199-
Crumb crumb = get("/crumbIssuer", Crumb.class);
219+
Crumb crumb = getQuietly("/crumbIssuer", Crumb.class);
200220
if (crumb != null) {
201221
request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb()));
202222
}
@@ -246,7 +266,7 @@ public String post_xml(String path, String xml_data) throws IOException {
246266
public String post_xml(String path, String xml_data, boolean crumbFlag) throws IOException {
247267
HttpPost request = new HttpPost(api(path));
248268
if (crumbFlag == true) {
249-
Crumb crumb = get("/crumbIssuer", Crumb.class);
269+
Crumb crumb = getQuietly("/crumbIssuer", Crumb.class);
250270
if (crumb != null) {
251271
request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb()));
252272
}

0 commit comments

Comments
 (0)