Commit 5f3b95e116fe70a8e647b1605dea60a3713910cf
Committed by
Paulo Meireles
1 parent
3cb6f6bb
Exists in
master
and in
23 other branches
[Mezuro] Added new way of handling exceptions: error_page
Showing
5 changed files
with
21 additions
and
20 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
| @@ -2,11 +2,17 @@ class MezuroPluginMyprofileController < ProfileController | @@ -2,11 +2,17 @@ class MezuroPluginMyprofileController < ProfileController | ||
| 2 | 2 | ||
| 3 | append_view_path File.join(File.dirname(__FILE__) + '/../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../views') |
| 4 | 4 | ||
| 5 | - | 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 | + | ||
| 6 | def choose_base_tool | 13 | def choose_base_tool |
| 7 | @configuration_content = profile.articles.find(params[:id]) | 14 | @configuration_content = profile.articles.find(params[:id]) |
| 8 | @base_tools = Kalibro::BaseTool.all_names | 15 | @base_tools = Kalibro::BaseTool.all_names |
| 9 | - @base_tools = [] if @base_tools.first.is_a? Exception | ||
| 10 | end | 16 | end |
| 11 | 17 | ||
| 12 | def choose_metric | 18 | def choose_metric |
| @@ -15,17 +21,17 @@ class MezuroPluginMyprofileController < ProfileController | @@ -15,17 +21,17 @@ class MezuroPluginMyprofileController < ProfileController | ||
| 15 | base_tool = Kalibro::BaseTool.find_by_name(@base_tool) | 21 | base_tool = Kalibro::BaseTool.find_by_name(@base_tool) |
| 16 | @supported_metrics = base_tool.nil? ? [] : base_tool.supported_metrics | 22 | @supported_metrics = base_tool.nil? ? [] : base_tool.supported_metrics |
| 17 | end | 23 | end |
| 18 | - | 24 | + |
| 19 | def new_metric_configuration | 25 | def new_metric_configuration |
| 20 | @configuration_content = profile.articles.find(params[:id]) | 26 | @configuration_content = profile.articles.find(params[:id]) |
| 21 | @metric = Kalibro::BaseTool.find_by_name(params[:base_tool]).metric params[:metric_name] | 27 | @metric = Kalibro::BaseTool.find_by_name(params[:base_tool]).metric params[:metric_name] |
| 22 | end | 28 | end |
| 23 | - | 29 | + |
| 24 | def new_compound_metric_configuration | 30 | def new_compound_metric_configuration |
| 25 | @configuration_content = profile.articles.find(params[:id]) | 31 | @configuration_content = profile.articles.find(params[:id]) |
| 26 | @metric_configurations = @configuration_content.metric_configurations | 32 | @metric_configurations = @configuration_content.metric_configurations |
| 27 | end | 33 | end |
| 28 | - | 34 | + |
| 29 | def edit_metric_configuration | 35 | def edit_metric_configuration |
| 30 | @configuration_content = profile.articles.find(params[:id]) | 36 | @configuration_content = profile.articles.find(params[:id]) |
| 31 | @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name]) | 37 | @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name]) |
plugins/mezuro/lib/kalibro/base_tool.rb
| @@ -3,19 +3,11 @@ class Kalibro::BaseTool < Kalibro::Model | @@ -3,19 +3,11 @@ class Kalibro::BaseTool < Kalibro::Model | ||
| 3 | attr_accessor :name, :description, :supported_metric | 3 | attr_accessor :name, :description, :supported_metric |
| 4 | 4 | ||
| 5 | def self.all_names | 5 | def self.all_names |
| 6 | - begin | ||
| 7 | - request("BaseTool", :get_base_tool_names)[:base_tool_name].to_a | ||
| 8 | - rescue Exception => exception | ||
| 9 | - [exception] | ||
| 10 | - end | 6 | + request("BaseTool", :get_base_tool_names)[:base_tool_name].to_a |
| 11 | end | 7 | end |
| 12 | 8 | ||
| 13 | def self.find_by_name(base_tool_name) | 9 | def self.find_by_name(base_tool_name) |
| 14 | - begin | ||
| 15 | - new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] | ||
| 16 | - rescue Exception | ||
| 17 | - nil | ||
| 18 | - end | 10 | + new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] |
| 19 | end | 11 | end |
| 20 | 12 | ||
| 21 | def supported_metric=(value) | 13 | def supported_metric=(value) |
plugins/mezuro/lib/kalibro/configuration.rb
| @@ -21,7 +21,7 @@ class Kalibro::Configuration < Kalibro::Model | @@ -21,7 +21,7 @@ class Kalibro::Configuration < Kalibro::Model | ||
| 21 | def self.find_by_name(configuration_name) | 21 | def self.find_by_name(configuration_name) |
| 22 | begin | 22 | begin |
| 23 | new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration] | 23 | new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration] |
| 24 | - rescue Exception => error | 24 | + rescue Exception |
| 25 | nil | 25 | nil |
| 26 | end | 26 | end |
| 27 | end | 27 | end |
plugins/mezuro/lib/kalibro/model.rb
| @@ -60,11 +60,11 @@ class Kalibro::Model | @@ -60,11 +60,11 @@ class Kalibro::Model | ||
| 60 | end | 60 | end |
| 61 | 61 | ||
| 62 | def destroy | 62 | def destroy |
| 63 | - # begin | 63 | + begin |
| 64 | self.class.request(destroy_endpoint, destroy_action, destroy_params) | 64 | self.class.request(destroy_endpoint, destroy_action, destroy_params) |
| 65 | - #rescue Exception => exception | ||
| 66 | - # add_error exception | ||
| 67 | - #end | 65 | + rescue Exception => exception |
| 66 | + add_error exception | ||
| 67 | + end | ||
| 68 | end | 68 | end |
| 69 | 69 | ||
| 70 | protected | 70 | protected |
plugins/mezuro/views/mezuro_plugin_myprofile/error_page.html.erb
0 → 100644