Skip to content

Commit 403adaa

Browse files
authored
Merge pull request #125 from dwasinge/exception-logging
Reduce Exception Logging For Status Not Found
2 parents e8d294d + ece2b70 commit 403adaa

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/main/java/com/redhat/labs/lodestar/resource/EngagementResource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ public Response findAllProjectHooks(@PathParam("customer") String customer,
157157
@Timed(name = "performedStatusGet", description = "Time to get status", unit = MetricUnits.MILLISECONDS)
158158
public Response getStatus(@PathParam("customer") String customer, @PathParam("engagement") String engagement) {
159159

160-
Status status = engagementService.getProjectStatus(customer, engagement);
161-
return Response.ok().entity(status).build();
160+
Optional<Status> status = engagementService.getProjectStatus(customer, engagement);
161+
if(status.isPresent()) {
162+
return Response.ok().entity(status).build();
163+
}
164+
return Response.status(404).build();
162165

163166
}
164167

src/main/java/com/redhat/labs/lodestar/service/EngagementService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import javax.annotation.PostConstruct;
1313
import javax.enterprise.context.ApplicationScoped;
1414
import javax.inject.Inject;
15-
import javax.ws.rs.WebApplicationException;
1615
import javax.ws.rs.core.Response;
1716

1817
import org.eclipse.microprofile.config.inject.ConfigProperty;
@@ -191,7 +190,7 @@ private Status getProjectStatusFile(String customerName, String engagementName)
191190
return status;
192191
}
193192

194-
public Status getProjectStatus(String customerName, String engagementName) {
193+
public Optional<Status> getProjectStatus(String customerName, String engagementName) {
195194

196195
List<ProjectTreeNode> nodes = projectService
197196
.getProjectTree(GitLabPathUtils.getValidPath(engagementPathPrefix, customerName, engagementName));
@@ -200,11 +199,11 @@ public Status getProjectStatus(String customerName, String engagementName) {
200199
List<ProjectTreeNode> status = nodes.stream().filter(node -> STATUS_FILE.equals(node.getName()))
201200
.collect(Collectors.toList());
202201
if (status.isEmpty()) {
203-
throw new WebApplicationException("failed to find status.json", 404);
202+
return Optional.empty();
204203
}
205204

206205
// get status
207-
return getProjectStatusFile(customerName, engagementName);
206+
return Optional.of(getProjectStatusFile(customerName, engagementName));
208207

209208
}
210209

src/test/java/com/redhat/labs/lodestar/service/EngagementServiceTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.Arrays;
1212
import java.util.List;
13+
import java.util.Optional;
1314

1415
import javax.inject.Inject;
1516
import javax.ws.rs.WebApplicationException;
@@ -23,6 +24,7 @@
2324

2425
import com.redhat.labs.lodestar.exception.UnexpectedGitLabResponseException;
2526
import com.redhat.labs.lodestar.models.Engagement;
27+
import com.redhat.labs.lodestar.models.Status;
2628
import com.redhat.labs.lodestar.models.gitlab.Group;
2729
import com.redhat.labs.lodestar.models.gitlab.Hook;
2830
import com.redhat.labs.lodestar.models.gitlab.Project;
@@ -191,12 +193,9 @@ void setup() {
191193
given(gitLabService.getProjectTree(Mockito.anyString(), Mockito.anyBoolean())).willReturn(r);
192194
given(gitLabService.getFile(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).willReturn(null);
193195

194-
WebApplicationException exception = assertThrows(WebApplicationException.class, () -> {
195-
engagementService.getProjectStatus("nope", "nada");
196-
});
196+
Optional<Status> status = engagementService.getProjectStatus("nope", "nada");
197197

198-
assertEquals(404, exception.getResponse().getStatus());
199-
assertEquals("failed to find status.json", exception.getMessage());
198+
assertTrue(status.isEmpty());
200199

201200
}
202201

0 commit comments

Comments
 (0)