Skip to content

Commit 91f1885

Browse files
authored
Merge pull request #594 from gsmet/handle-service-down-exceptions
Handle ServiceDownException by providing a proper error message
2 parents 8712957 + f2438ba commit 91f1885

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

runtime/src/main/java/io/quarkiverse/githubapp/runtime/error/DefaultErrorHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
import org.jboss.logging.Logger;
99
import org.kohsuke.github.GHEventPayload;
10+
import org.kohsuke.github.ServiceDownException;
1011

1112
import io.quarkiverse.githubapp.GitHubEvent;
1213
import io.quarkiverse.githubapp.error.ErrorHandler;
14+
import io.quarkiverse.githubapp.runtime.github.GitHubServiceDownException;
1315
import io.quarkiverse.githubapp.runtime.github.PayloadHelper;
1416
import io.quarkus.arc.DefaultBean;
1517
import io.quarkus.runtime.LaunchMode;
@@ -29,6 +31,10 @@ public class DefaultErrorHandler implements ErrorHandler {
2931
public void handleError(GitHubEvent gitHubEvent, GHEventPayload payload, Throwable t) {
3032
StringBuilder errorMessage = new StringBuilder();
3133
errorMessage.append("Error handling delivery " + gitHubEvent.getDeliveryId() + "\n");
34+
if (t instanceof ServiceDownException || t instanceof GitHubServiceDownException) {
35+
errorMessage
36+
.append("››› GitHub APIs are not available at the moment. Have a look at https://www.githubstatus.com.\n");
37+
}
3238
if (gitHubEvent.getRepository().isPresent()) {
3339
errorMessage.append("› Repository: " + gitHubEvent.getRepository().get() + "\n");
3440
}

runtime/src/main/java/io/quarkiverse/githubapp/runtime/github/GitHubFileDownloader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.kohsuke.github.GHContent;
1111
import org.kohsuke.github.GHFileNotFoundException;
1212
import org.kohsuke.github.GHRepository;
13+
import org.kohsuke.github.ServiceDownException;
1314

1415
import io.quarkus.runtime.LaunchMode;
1516

@@ -35,6 +36,9 @@ public Optional<String> getFileContent(GHRepository ghRepository, String ref, St
3536
+ ". Either the file does not exist or the 'Contents' permission has not been set for the application.");
3637
}
3738
return Optional.empty();
39+
} catch (ServiceDownException e) {
40+
throw new GitHubServiceDownException(
41+
"Error downloading file " + fullPath + " for repository " + ghRepository.getFullName());
3842
} catch (IOException e) {
3943
throw new IllegalStateException(
4044
"Error downloading file " + fullPath + " for repository " + ghRepository.getFullName(), e);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.quarkiverse.githubapp.runtime.github;
2+
3+
public class GitHubServiceDownException extends RuntimeException {
4+
5+
public GitHubServiceDownException(String message) {
6+
super(message);
7+
}
8+
}

0 commit comments

Comments
 (0)