Skip to content

Commit 1edc909

Browse files
authored
Merge pull request #12 from Visual-Regression-Tracker/77-exceptions-handle
403 error added
2 parents d912bbc + 83c791e commit 1edc909

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/main/java/io/visual_regression_tracker/sdk_java/VisualRegressionTracker.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ protected void startBuild() throws IOException {
4545
.build();
4646

4747
try (Response response = client.newCall(request).execute()) {
48-
if (response.code() == 404) {
49-
throw new TestRunException("Project not found");
50-
}
5148
if (response.code() == 401) {
5249
throw new TestRunException("Unauthorized");
5350
}
51+
if (response.code() == 403) {
52+
throw new TestRunException("Api key not authenticated");
53+
}
54+
if (response.code() == 404) {
55+
throw new TestRunException("Project not found");
56+
}
5457

5558
String responseBody = Optional.ofNullable(response.body())
5659
.orElseThrow(() -> new TestRunException("Cannot get response body"))

src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ public void shouldThrowExceptionIfUnauthorized() throws IOException {
102102
MatcherAssert.assertThat(exceptionMessage, CoreMatchers.is("Unauthorized"));
103103
}
104104

105+
@Test
106+
public void shouldThrowExceptionIfForbidden() throws IOException {
107+
server.enqueue(new MockResponse()
108+
.setResponseCode(403)
109+
.setBody("{\r\n \"statusCode\": 403,\r\n \"message\": \"Forbidden\"\r\n}"));
110+
111+
String exceptionMessage = "";
112+
try {
113+
vrt.startBuild();
114+
} catch (TestRunException ex) {
115+
exceptionMessage = ex.getMessage();
116+
}
117+
MatcherAssert.assertThat(exceptionMessage, CoreMatchers.is("Api key not authenticated"));
118+
}
119+
105120
@Test
106121
public void shouldSubmitTestRun() throws IOException, InterruptedException {
107122
String buildId = "123123";

0 commit comments

Comments
 (0)