Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octokitの例外が発生した場合はCommandFailedをraiseしてほしい #1

Open
vividtone opened this issue Sep 12, 2023 · 0 comments

Comments

@vividtone
Copy link
Contributor

すべてのOctKitの呼び出しについて、Octokit::Error例外を捕捉してCommandFailed例外をraiseしてほしいです。目的はRedmineの画面にエラーメッセージが表示されるようにするためです。

以下、サンプルです。

diff --git a/lib/redmine/scm/adapters/github_adapter.rb b/lib/redmine/scm/adapters/github_adapter.rb
index 647ba51..63e1c3b 100644
--- a/lib/redmine/scm/adapters/github_adapter.rb
+++ b/lib/redmine/scm/adapters/github_adapter.rb
@@ -37,6 +37,11 @@ module Redmine
             end
           end
           @branches.sort!
+        rescue Octokit::Error => e
+          logger.error "scm: github: error: #{e.message}"
+          gh_error = JSON.parse(e.response_body.to_s)['message'].presence
+          emsg = gh_error ? 'error response from GitHub: ' + gh_error : ''
+          raise CommandFailed, emsg
         end
 
         def entries(path=nil, identifier=nil, options={})
圖片
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant