Skip to content

Commit

Permalink
Merge pull request #7 from valfirst/clean-up-remove-immediate-rethrow…
Browse files Browse the repository at this point in the history
…s-of-caught-exceptions

Clean up: remove immediate rethrows of caught exceptions
  • Loading branch information
francisf authored Dec 18, 2020
2 parents b22e330 + 9c3f319 commit ef2cbd5
Showing 1 changed file with 11 additions and 35 deletions.
46 changes: 11 additions & 35 deletions src/main/java/com/browserstack/client/BrowserStackClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,7 @@ public List<Build> getBuilds(final BuildStatus status, final int limit, final St
httpRequest.queryString(Constants.Filter.BUILD_NAME, buildName);
}

final List<BuildNode> buildNodes;
try {
buildNodes = Arrays.asList(httpRequest.asObject(BuildNode[].class));
} catch (BrowserStackException e) {
throw e;
}
final List<BuildNode> buildNodes = Arrays.asList(httpRequest.asObject(BuildNode[].class));

final List<Build> builds = new ArrayList<Build>();
for (BuildNode buildNode : buildNodes) {
Expand Down Expand Up @@ -405,8 +400,6 @@ public Build getBuild(final String buildId) throws BuildNotFound, BrowserStackEx
return buildNode.getBuild().setClient(this);
} catch (BrowserStackObjectNotFound e) {
throw new BuildNotFound("Build not found: " + buildId);
} catch (BrowserStackException e) {
throw e;
}
}

Expand All @@ -419,15 +412,11 @@ public Build getBuild(final String buildId) throws BuildNotFound, BrowserStackEx
* @throws BrowserStackException
*/
public Build getBuildByName(@Nonnull final String buildName) throws BuildNotFound, BrowserStackException {
try {
final List<Build> build = getBuilds(null, 1, buildName);
if (build.size() == 1) {
return build.get(0);
}
throw new BuildNotFound("Build not found by name: " + buildName);
} catch (BrowserStackException e) {
throw e;
final List<Build> build = getBuilds(null, 1, buildName);
if (build.size() == 1) {
return build.get(0);
}
throw new BuildNotFound("Build not found by name: " + buildName);
}

/**
Expand All @@ -438,15 +427,11 @@ public Build getBuildByName(@Nonnull final String buildName) throws BuildNotFoun
* @throws BrowserStackException
*/
public boolean deleteBuild(final String buildId) throws BrowserStackException {
try {
ObjectNode result = newRequest(BrowserStackClient.Method.DELETE, "/builds/{buildId}.json")
.routeParam("buildId", buildId).asJsonObject();
ObjectNode result = newRequest(Method.DELETE, "/builds/{buildId}.json")
.routeParam("buildId", buildId).asJsonObject();

String status = (result != null) ? result.path("status").asText() : null;
return (status != null && status.equals("ok"));
} catch (BrowserStackException e) {
throw e;
}
String status = (result != null) ? result.path("status").asText() : null;
return (status != null && status.equals("ok"));
}

/**
Expand Down Expand Up @@ -497,13 +482,8 @@ public List<Session> getSessions(final String buildId, final BuildStatus status,
}

private List<SessionNode> getSessionNodes(String buildId, BuildStatus status, int totalLimit, int offset) throws BrowserStackException {
BrowserStackRequest httpRequest;
try {
httpRequest =
newRequest(Method.GET, "/builds/{buildId}/sessions.json").routeParam("buildId", buildId);
} catch (BrowserStackException e) {
throw e;
}
BrowserStackRequest httpRequest = newRequest(Method.GET, "/builds/{buildId}/sessions.json").routeParam(
"buildId", buildId);

httpRequest.queryString(Constants.Filter.LIMIT, totalLimit);
httpRequest.queryString(Constants.Filter.OFFSET, offset);
Expand All @@ -517,8 +497,6 @@ private List<SessionNode> getSessionNodes(String buildId, BuildStatus status, in
sessionNodes = Arrays.asList(httpRequest.asObject(SessionNode[].class));
} catch (BrowserStackObjectNotFound e) {
throw new BuildNotFound("Build not found: " + buildId);
} catch (BrowserStackException e) {
throw e;
}
return sessionNodes;
}
Expand Down Expand Up @@ -583,8 +561,6 @@ public Session getSession(String sessionId) throws SessionNotFound, BrowserStack
return sessionNode.getSession().setClient(this);
} catch (BrowserStackObjectNotFound e) {
throw new SessionNotFound("Session not found: " + sessionId);
} catch (BrowserStackException e) {
throw e;
}
}

Expand Down

0 comments on commit ef2cbd5

Please sign in to comment.