Skip to content

Commit

Permalink
Merge pull request #61 from helenabutowatep/json-exception-handling
Browse files Browse the repository at this point in the history
If console output looks like it might be JSON but it turns out it isn't, return the ConnectionResponse.
  • Loading branch information
cashlalala committed Nov 20, 2019
2 parents 83a8c0a + d0f2739 commit 4642fc6
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import hudson.AbortException;
import hudson.ProxyConfiguration;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import net.sf.json.util.JSONUtils;
Expand Down Expand Up @@ -123,7 +124,7 @@ public static String buildUrlQueryString(Collection<String> parameters) {
/**
* Same as above, but takes in to consideration if the remote server has any
* default parameters set or not
*
*
* @param isRemoteJobParameterized
* Boolean indicating if the remote job is parameterized or not
* @return A string which represents a portion of the build URL
Expand Down Expand Up @@ -410,7 +411,7 @@ public static String buildTriggerUrl(String jobNameOrUrl, String securityToken,

return triggerUrlString;
}

/**
* Same as sendHTTPCall, but keeps track of the number of failed connection
* attempts (aka: the number of times this method has been called). In the case
Expand Down Expand Up @@ -440,7 +441,7 @@ public static String buildTriggerUrl(String jobNameOrUrl, String securityToken,
* all the possibilities of HTTP exceptions
* @throws InterruptedException
* if any thread has interrupted the current thread.
*
*
*/
private static ConnectionResponse sendHTTPCall(String urlString, String requestType, BuildContext context,
Collection<String> postParams, int numberOfAttempts, int pollInterval, int retryLimit, Auth2 overrideAuth,
Expand Down Expand Up @@ -523,7 +524,13 @@ private static ConnectionResponse sendHTTPCall(String urlString, String requestT
if (responseCode >= 400 || !JSONUtils.mayBeJSON(response)) {
return new ConnectionResponse(responseHeader, response, responseCode);
} else {
responseObject = (JSONObject) JSONSerializer.toJSON(response);
try {
responseObject = (JSONObject) JSONSerializer.toJSON(response);
}
catch(JSONException e) {
// despite JSONUtils.mayBeJSON believing that this might be JSON, it looks like it wasn't
return new ConnectionResponse(responseHeader, response, responseCode);
}
}
}

Expand Down

0 comments on commit 4642fc6

Please sign in to comment.