Commit feec92ee4ebab38220c6a8577a47009b2f83beee
Committed by
Paulo Meireles
1 parent
5f3b95e1
Exists in
master
and in
29 other branches
[Mezuro] refactoring Handling Exceptions
Showing
7 changed files
with
40 additions
and
29 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
1 | 1 | class MezuroPluginProfileController < ProfileController |
2 | 2 | |
3 | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../views') |
4 | - | |
4 | + | |
5 | + rescue_from Exception do |exception| | |
6 | + message = URI.escape(CGI.escape(exception.message),'.') | |
7 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}" | |
8 | + end | |
9 | + | |
10 | + def error_page | |
11 | + end | |
12 | + | |
5 | 13 | def project_state |
6 | 14 | @content = profile.articles.find(params[:id]) |
7 | 15 | project = @content.project | ... | ... |
plugins/mezuro/lib/kalibro/configuration.rb
... | ... | @@ -7,11 +7,7 @@ class Kalibro::Configuration < Kalibro::Model |
7 | 7 | end |
8 | 8 | |
9 | 9 | def metric_configurations |
10 | - if @metric_configuration != nil | |
11 | - @metric_configuration | |
12 | - else | |
13 | - [] | |
14 | - end | |
10 | + @metric_configuration.nil? ? [] : @metric_configuration | |
15 | 11 | end |
16 | 12 | |
17 | 13 | def metric_configurations=(metric_configurations) |
... | ... | @@ -19,19 +15,11 @@ class Kalibro::Configuration < Kalibro::Model |
19 | 15 | end |
20 | 16 | |
21 | 17 | def self.find_by_name(configuration_name) |
22 | - begin | |
23 | - new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration] | |
24 | - rescue Exception | |
25 | - nil | |
26 | - end | |
18 | + new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration] | |
27 | 19 | end |
28 | 20 | |
29 | 21 | def self.all_names |
30 | - begin | |
31 | - request("Configuration", :get_configuration_names)[:configuration_name] | |
32 | - rescue Exception | |
33 | - [] | |
34 | - end | |
22 | + request("Configuration", :get_configuration_names)[:configuration_name] | |
35 | 23 | end |
36 | 24 | |
37 | 25 | def update_attributes(attributes={}) | ... | ... |
plugins/mezuro/lib/kalibro/error.rb
... | ... | @@ -2,10 +2,6 @@ class Kalibro::Error < Kalibro::Model |
2 | 2 | |
3 | 3 | attr_accessor :error_class, :message, :stack_trace_element, :cause |
4 | 4 | |
5 | - def initialize(exception) | |
6 | - @message = exception.message | |
7 | - end | |
8 | - | |
9 | 5 | def stack_trace_element=(value) |
10 | 6 | @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value |
11 | 7 | end | ... | ... |
plugins/mezuro/lib/kalibro/metric_configuration.rb
... | ... | @@ -49,10 +49,14 @@ class Kalibro::MetricConfiguration < Kalibro::Model |
49 | 49 | end |
50 | 50 | |
51 | 51 | def destroy |
52 | - self.class.request("MetricConfiguration", :remove_metric_configuration, { | |
52 | + begin | |
53 | + self.class.request("MetricConfiguration", :remove_metric_configuration, { | |
53 | 54 | :configuration_name => configuration_name, |
54 | 55 | :metric_name=> metric.name |
55 | 56 | }) |
57 | + rescue Exception => exception | |
58 | + add_error exception | |
59 | + end | |
56 | 60 | end |
57 | 61 | |
58 | 62 | def to_hash | ... | ... |
plugins/mezuro/lib/kalibro/model.rb
plugins/mezuro/lib/kalibro/project.rb
... | ... | @@ -19,19 +19,31 @@ class Kalibro::Project < Kalibro::Model |
19 | 19 | end |
20 | 20 | |
21 | 21 | def process_project(days = '0') |
22 | - if days.to_i.zero? | |
23 | - self.class.request("Kalibro", :process_project, {:project_name => name}) | |
24 | - else | |
25 | - self.class.request("Kalibro", :process_periodically, {:project_name => name, :period_in_days => days}) | |
26 | - end | |
22 | + begin | |
23 | + if days.to_i.zero? | |
24 | + self.class.request("Kalibro", :process_project, {:project_name => name}) | |
25 | + else | |
26 | + self.class.request("Kalibro", :process_periodically, {:project_name => name, :period_in_days => days}) | |
27 | + end | |
28 | + rescue Exception => exception | |
29 | + add_error exception | |
30 | + end | |
27 | 31 | end |
28 | 32 | |
29 | 33 | def process_period |
30 | - self.class.request("Kalibro", :get_process_period, {:project_name => name})[:period] | |
34 | + begin | |
35 | + self.class.request("Kalibro", :get_process_period, {:project_name => name})[:period] | |
36 | + rescue Exception => exception | |
37 | + add_error exception | |
38 | + end | |
31 | 39 | end |
32 | 40 | |
33 | 41 | def cancel_periodic_process |
34 | - self.class.request("Kalibro", :cancel_periodic_process, {:project_name => name}) | |
42 | + begin | |
43 | + self.class.request("Kalibro", :cancel_periodic_process, {:project_name => name}) | |
44 | + rescue Exception => exception | |
45 | + add_error exception | |
46 | + end | |
35 | 47 | end |
36 | 48 | |
37 | 49 | end | ... | ... |
plugins/mezuro/test/unit/kalibro/configuration_test.rb
... | ... | @@ -44,7 +44,9 @@ class ConfigurationTest < ActiveSupport::TestCase |
44 | 44 | should 'return nil when configuration doesnt exist' do |
45 | 45 | request_body = {:configuration_name => @configuration.name} |
46 | 46 | Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).raises(Exception.new) |
47 | - assert_nil Kalibro::Configuration.find_by_name(@configuration.name) | |
47 | + assert_raise Exception do | |
48 | + Kalibro::Configuration.find_by_name(@configuration.name) | |
49 | + end | |
48 | 50 | end |
49 | 51 | |
50 | 52 | should 'destroy configuration by name' do | ... | ... |