-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rescue gitlab and octokit exceptions
- Loading branch information
1 parent
b36fc16
commit b9ef94c
Showing
3 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class SCMExceptionHandler | ||
include ActiveSupport::Rescuable | ||
attr_accessor :event_payload, :event_subscription_payload | ||
|
||
rescue_from Octokit::AbuseDetected, | ||
Octokit::AccountSuspended, | ||
Octokit::BillingIssue, | ||
Octokit::BranchNotProtected, | ||
Octokit::Conflict, | ||
Octokit::Forbidden, | ||
Octokit::RepositoryUnavailable, | ||
Octokit::NotFound, | ||
Octokit::OneTimePasswordRequired, | ||
Octokit::Unauthorized, | ||
Octokit::UnavailableForLegalReasons, | ||
Octokit::UnsupportedMediaType, | ||
Octokit::CommitIsNotPartOfPullRequest, | ||
Octokit::InstallationSuspended, | ||
Octokit::SAMLProtected, | ||
Octokit::TooLargeContent, | ||
Octokit::TooManyLoginAttempts, | ||
Octokit::UnverifiedEmail, | ||
Octokit::InvalidRepository, | ||
Octokit::PathDiffTooLarge, | ||
Octokit::ServiceUnavailable, | ||
Octokit::InternalServerError do |exception| | ||
# FIXME: Inform users about the exceptions | ||
log(exception) | ||
end | ||
|
||
rescue_from Gitlab::Error::Conflict, | ||
Gitlab::Error::Forbidden, | ||
Gitlab::Error::InternalServerError, | ||
Gitlab::Error::MissingCredentials, | ||
Gitlab::Error::NotFound, | ||
Gitlab::Error::ServiceUnavailable, | ||
Gitlab::Error::TooManyRequests, | ||
Gitlab::Error::Unauthorized do |exception| | ||
# FIXME: Inform users about the exceptions | ||
log(exception) | ||
end | ||
|
||
def initialize(event_payload, event_subscription_payload, scm_token) | ||
@event_payload = event_payload.deep_symbolize_keys | ||
@event_subscription_payload = event_subscription_payload.deep_symbolize_keys | ||
@scm_token = scm_token | ||
end | ||
|
||
private | ||
|
||
def log(exception) | ||
token = Token::Workflow.find_by(scm_token: @scm_token) | ||
Rails.logger.error "#{exception.class}: #{exception.message}. TokenID: #{token.id}, User: #{token.user.login}, Event Subscription Payload: #{@event_subscription_payload}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters