Error getting notification
While retrieving notifications it's throwing errors described below for the code listed below.
org.kohsuke.github.HttpException: {"message":"Unable to parse If-Modified-Since request header. Please make sure value is in an acceptable format.","documentation_url":"https://docs.github.com/rest/reference/activity#list-notifications-for-the-authenticated-user"}
at org.kohsuke.github.GitHubConnectorResponseErrorHandler$1.onError(GitHubConnectorResponseErrorHandler.java:56) ~[github-api-1.306.jar:na]
at org.kohsuke.github.GitHubClient.detectKnownErrors(GitHubClient.java:424) ~[github-api-1.306.jar:na]
at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:386) ~[github-api-1.306.jar:na]
at org.kohsuke.github.GitHubPageIterator.fetch(GitHubPageIterator.java:142) ~[github-api-1.306.jar:na]
at org.kohsuke.github.GitHubPageIterator.hasNext(GitHubPageIterator.java:89) ~[github-api-1.306.jar:na]
at org.kohsuke.github.PagedIterator.fetch(PagedIterator.java:106) ~[github-api-1.306.jar:na]
at org.kohsuke.github.PagedIterator.nextPageArray(PagedIterator.java:134) ~[github-api-1.306.jar:na]
at org.kohsuke.github.PagedIterable.toArray(PagedIterable.java:78) ~[github-api-1.306.jar:na]
at org.kohsuke.github.GitHubPageContentsIterable.toResponse(GitHubPageContentsIterable.java:58) ~[github-api-1.306.jar:na]
at org.kohsuke.github.GHNotificationStream$1.fetch(GHNotificationStream.java:183) ~[github-api-1.306.jar:na]
at org.kohsuke.github.GHNotificationStream$1.hasNext(GHNotificationStream.java:149) ~[github-api-1.306.jar:na]
**The line of code where I am getting error is
GHNotificationStream notificationStream = gitHub.listNotifications();
for (GHThread ghThread : notificationStream){
Map<String, String> notification = new HashMap<>();
notification.put("type", ghThread.getType());
notification.put("title", ghThread.getTitle());
notification.put("reason", ghThread.getReason());
notification.put("createdAt", String.valueOf(ghThread.getCreatedAt()));
notification.put("updatedAt", String.valueOf(ghThread.getUpdatedAt()));
notification.put("repository", ghThread.getRepository().getName());
notificationList.add(notification);
}
I am not sure about the real cause of it but it's maybe caused due to the 'null' value passing in lastModified variable in org.kohsuke.github.GHNotificationStream class line number: 107 of below snippet,
if (this.nextCheckTime < now) {
req.setHeader("If-Modified-Since", `this.lastModified);
Requester requester = (Requester)req.withUrlPath(GHNotificationStream.this.apiUrl, new String[0]);
GitHubResponse<GHThread[]> response = ((GitHubPageContentsIterable)requester.toIterable(GHThread[].class, (Consumer)null)).toResponse();
this.threads = (GHThread[])response.body();
if (this.threads == null) {
this.threads = GHNotificationStream.EMPTY_ARRAY;
} else {
++this.lastUpdated;
}
Expected behavior A GHThread value should be given in return but throwing HttpException indicating the value of the header "If-Modified-Since" is null.
There's definitely a bug in the library .
We have a test for this, so it is likely that the API changed and the library needs updating.
Just had the same issue. I updated to the newest version v1.319 which just came out this month. Strange, because I still see new updates to this library but this bug seems pretty simple and is years old. Is this library only partially being maintained?
@mgroth0
this bug seems pretty simple and is years old. Is this library only partially being maintained?
Hm, https://github.com/hub4j/github-api/graphs/commit-activity indicates a steady stream of commits. Perhaps you'd like to add your name to the list people who have contributed to this project?
@bitwiseman sorry that my comment came off a bit snarky. I didn't mean to.
I think that the amount of setup (with setting up credentials and to do all the proper testing) is bit much for me. I made my request with HTTP directly and it works for my use case, so I no longer need this.
However, I can say my idea in case it helps.
It is about this line.
https://github.com/hub4j/github-api/blob/eb269bd12b7998015dc96f000ce625f90a1c5926/src/main/java/org/kohsuke/github/GHNotificationStream.java#L190
req.setHeader("If-Modified-Since", lastModified);
It seems that lastModified might be null the first time, and I wonder if github doesn't like the null or blank header value. I wonder if we just tried this:
if (lastModified!=null) {
req.setHeader("If-Modified-Since", lastModified);
}
@mgroth0 My apologies for my return-snarking. 😄 Thanks for taking time to add some details/suggestion. When someone has the time to look at this it will help them get started.