From f6a3acf2f0b48e51f9b03d2d0d20728dfbfd0e25 Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Tue, 10 Dec 2013 10:53:30 +0200 Subject: [PATCH] fix exceptions --- README.rdoc | 2 +- app/helpers/washout_builder_helper.rb | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.rdoc b/README.rdoc index 741952b..b6a07a0 100644 --- a/README.rdoc +++ b/README.rdoc @@ -61,7 +61,7 @@ Please read {release details}[https://github.com/bogdanRada/washout_builder/rele The way soap_actions, or reusable types are defined or how the configuration is made using WashOut(https://github.com/inossidabile/wash_out) haven't changed You can still do everything that gem does . -When specifying the soap_action you can also pass a option for description and a list of exceptions(need to be instances as example) that the method can raise at a certain moment. +When specifying the soap_action you can also pass a option for description and a list of exceptions(need to be instances) that the method can raise at a certain moment. The exception classes used must inherit from WashOut::SOAPError, which has by default a error code and a message as attributes but you can extend it by adding more accessible_attributes to your own custom class. diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index 3e90dce..e04aaae 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -64,14 +64,14 @@ def fix_descendant_wash_out_type(param, complex_class) if !param_class.nil? && param_class.ancestors.include?(WashOut::Type) && !param.map[0].nil? descendant = WashOut::Param.parse_def(@soap_config, param_class.wash_out_param_map)[0] param.name = descendant.name - param.map = descendant.map + param.map = descendant.map end end def get_nested_complex_types(param, defined) defined = [] if defined.blank? complex_class = get_complex_class_name(param, defined) - fix_descendant_wash_out_type(param, complex_class) + fix_descendant_wash_out_type(param, complex_class) defined << {:class =>complex_class, :obj => param, :ancestors => param.classified? ? get_class_ancestors(param, complex_class, defined) : nil } unless complex_class.nil? if param.struct? c_names = [] @@ -94,7 +94,8 @@ def get_complex_types(map) def get_fault_types_names(map) defined = map.select{|operation, formats| !formats[:raises].blank? } - defined.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten.map{|item| item.class.to_s }.sort_by { |name| name.downcase }.uniq unless defined.blank? + defined = defined.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten.select { |x| x.class.ancestors.include?(WashOut::SOAPError) } unless defined.blank? + defined.map{|item| item.class.to_s }.sort_by { |name| name.downcase }.uniq unless defined.blank? end def get_soap_action_names(map) @@ -151,8 +152,7 @@ def create_html_fault_types_details(xml, map) end def create_html_fault_type(xml, param) - ancestor_class = defined?(WashOut::Dispatcher::SOAPError) ? WashOut::Dispatcher::SOAPError : WashOut::SOAPError - if param.class.ancestors.include?(ancestor_class) + if param.class.ancestors.include?(WashOut::SOAPError) xml.h3 "#{param.class}" xml.a("name" => "#{param.class}") {} xml.ul("class" => "pre") { @@ -287,13 +287,16 @@ def create_html_public_method(xml, operation, formats) unless formats[:raises].blank? faults = formats[:raises] faults = [formats[:raises]] if !faults.is_a?(Array) - - xml.p "Exceptions:" - xml.ul { - faults.each do |p| - xml.li("class" => "pre"){ |y| y<< " #{p.class.to_s}" } - end - } + + faults = faults.select { |x| x.class.ancestors.include?(WashOut::SOAPError) } + unless faults.blank? + xml.p "Exceptions:" + xml.ul { + faults.each do |p| + xml.li("class" => "pre"){ |y| y<< " #{p.class.to_s}" } + end + } + end end end