Skip to content

Commit 23b21c9

Browse files
committed
Added handling and logging of invalid access levels (#163).
1 parent f252531 commit 23b21c9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/java/org/gitlab4j/api/GitLabApi.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Map;
55
import java.util.Optional;
66
import java.util.WeakHashMap;
7+
import java.util.logging.Logger;
78

89
import javax.ws.rs.core.MediaType;
910
import javax.ws.rs.core.Response;
@@ -22,6 +23,8 @@
2223
*/
2324
public class GitLabApi {
2425

26+
private final static Logger LOG = Logger.getLogger(GitLabApi.class.getName());
27+
2528
/** GitLab4J default per page. GitLab will ignore anything over 100. */
2629
public static final int DEFAULT_PER_PAGE = 100;
2730

@@ -68,6 +71,15 @@ public String getApiNamespace() {
6871
private NotesApi notesApi;
6972
private EventsApi eventsApi;
7073

74+
/**
75+
* Get the GitLab4J shared Logger instance.
76+
*
77+
* @return the GitLab4J shared Logger instance
78+
*/
79+
public static final Logger getLogger() {
80+
return (LOG);
81+
}
82+
7183
/**
7284
* Create a new GitLabApi instance that is logically a duplicate of this instance, with the exception off sudo state.
7385
*

src/main/java/org/gitlab4j/api/models/AccessLevel.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6+
import org.gitlab4j.api.GitLabApi;
7+
68
import com.fasterxml.jackson.annotation.JsonCreator;
79
import com.fasterxml.jackson.annotation.JsonValue;
810

911
public enum AccessLevel {
1012

11-
NONE(0), GUEST(10), REPORTER(20), DEVELOPER(30), MASTER(40), OWNER(50);
13+
INVALID(-1), NONE(0), GUEST(10), REPORTER(20), DEVELOPER(30), MASTER(40), OWNER(50);
1214

1315
public final Integer value;
1416

@@ -24,7 +26,14 @@ public enum AccessLevel {
2426

2527
@JsonCreator
2628
public static AccessLevel forValue(Integer value) {
27-
return valuesMap.get(value);
29+
30+
AccessLevel level = valuesMap.get(value);
31+
if (level != null) {
32+
return (level);
33+
}
34+
35+
GitLabApi.getLogger().warning(String.format("[%d] is not a valid GitLab access level.", value));
36+
return (value == null ? null : INVALID);
2837
}
2938

3039
@JsonValue

0 commit comments

Comments
 (0)