Skip to content

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

@vividtone

Description

@vividtone

すべての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={})
圖片

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions