Commit a2c93299edd31b31f6a0fa51a41a9b83110ca527
1 parent
41381ee2
Exists in
master
and in
1 other branch
Added error handling for issue trackers, display error message if something goes wrong
Showing
6 changed files
with
33 additions
and
20 deletions
Show diff stats
app/controllers/errs_controller.rb
| ... | ... | @@ -39,7 +39,11 @@ class ErrsController < ApplicationController |
| 39 | 39 | set_tracker_params |
| 40 | 40 | |
| 41 | 41 | if @app.issue_tracker |
| 42 | - @app.issue_tracker.create_issue @problem, current_user | |
| 42 | + begin | |
| 43 | + @app.issue_tracker.create_issue @problem, current_user | |
| 44 | + rescue IssueTrackers::IssueTrackerError => ex | |
| 45 | + flash[:error] = ex.message | |
| 46 | + end | |
| 43 | 47 | else |
| 44 | 48 | flash[:error] = "This app has no issue tracker setup." |
| 45 | 49 | end | ... | ... |
app/models/issue_trackers/github_issues_tracker.rb
| ... | ... | @@ -21,8 +21,12 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker |
| 21 | 21 | |
| 22 | 22 | def create_issue(problem, reported_by = nil) |
| 23 | 23 | client = Octokit::Client.new(:login => username, :password => password) |
| 24 | - issue = client.create_issue(project_id, issue_title(problem), body_template.result(binding).unpack('C*').pack('U*'), options = {}) | |
| 25 | - problem.update_attribute :issue_link, issue.issue.html_url | |
| 24 | + begin | |
| 25 | + issue = client.create_issue(project_id, issue_title(problem), body_template.result(binding).unpack('C*').pack('U*'), options = {}) | |
| 26 | + problem.update_attribute :issue_link, issue.issue.html_url | |
| 27 | + rescue Octokit::Unauthorized | |
| 28 | + raise IssueTrackers::AuthenticationError, "Could not authenticate with Github. Please check your username and password." | |
| 29 | + end | |
| 26 | 30 | end |
| 27 | 31 | |
| 28 | 32 | def body_template | ... | ... |
config/initializers/issue_trackers.rb
| ... | ... | @@ -2,5 +2,6 @@ |
| 2 | 2 | include IssueTrackers |
| 3 | 3 | |
| 4 | 4 | # Require all issue tracker apis in lib/issue_tracker_apis |
| 5 | -Dir.glob(Rails.root.join('lib/issue_tracker_apis/*.rb')).each {|t| require t } | |
| 6 | - | |
| 5 | +Dir.glob(Rails.root.join('lib/issue_trackers/apis/*.rb')).each {|t| require t } | |
| 6 | +# Require issue tracker error classes | |
| 7 | +require Rails.root.join('lib/issue_trackers/errors') | ... | ... |
lib/issue_tracker_apis/mingle.rb
| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | -module Mingle | |
| 2 | - class Card < ActiveResource::Base | |
| 3 | - # site template ~> "https://username:password@mingle.example.com/api/v1/projects/:project_id/" | |
| 4 | - self.format = :xml | |
| 5 | - end | |
| 6 | - def self.set_site(site) | |
| 7 | - # ActiveResource seems to clone and freeze the @site variable | |
| 8 | - # after the first use. It seems that the only way to change @site | |
| 9 | - # is to drop the subclass, and then reload it. | |
| 10 | - Mingle.send(:remove_const, :Card) | |
| 11 | - load File.join(Rails.root,'lib','issue_tracker_apis','mingle.rb') | |
| 12 | - Mingle::Card.site = site | |
| 13 | - end | |
| 14 | -end | |
| 15 | - |
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +module Mingle | |
| 2 | + class Card < ActiveResource::Base | |
| 3 | + # site template ~> "https://username:password@mingle.example.com/api/v1/projects/:project_id/" | |
| 4 | + self.format = :xml | |
| 5 | + end | |
| 6 | + def self.set_site(site) | |
| 7 | + # ActiveResource seems to clone and freeze the @site variable | |
| 8 | + # after the first use. It seems that the only way to change @site | |
| 9 | + # is to drop the subclass, and then reload it. | |
| 10 | + Mingle.send(:remove_const, :Card) | |
| 11 | + load File.join(Rails.root,'lib','issue_trackers', 'apis','mingle.rb') | |
| 12 | + Mingle::Card.site = site | |
| 13 | + end | |
| 14 | +end | |
| 15 | + | ... | ... |