Skip to content

Commit

Permalink
Don't use Exception, use StandardError
Browse files Browse the repository at this point in the history
It's bad Ruby practice to have Error classes inherit directly from
Exception, or to raise instances of Exception itself. It is highly
recommended that any custom error classes inherit instead from
StandardError. StandardError is also the go-to exception class for when
you need to raise an error without a custom class.

Signed-off-by: David Celis <[email protected]>
  • Loading branch information
davidcelis committed Mar 27, 2013
1 parent c0f38a1 commit 05376ed
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/onelogin/ruby-saml/logoutresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def valid_saml?(soft = true)
if soft
@schema.validate(@xml).map{ return false }
else
@schema.validate(@xml).map{ |error| raise(Exception.new("#{error.message}\n\n#{@xml.to_s}")) }
@schema.validate(@xml).map{ |error| raise(StandardError.new("#{error.message}\n\n#{@xml.to_s}")) }
end
end

Expand Down Expand Up @@ -151,4 +151,4 @@ def validation_error(message)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/validation_error.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Onelogin
module Saml
class ValidationError < Exception
class ValidationError < StandardError
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/logoutresponse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class RubySamlTest < Test::Unit::TestCase
should "raise error for invalid xml" do
logoutresponse = Onelogin::Saml::Logoutresponse.new(invalid_xml_response, settings)

assert_raises(Exception) { logoutresponse.validate! }
assert_raises(StandardError) { logoutresponse.validate! }
end
end

Expand Down

0 comments on commit 05376ed

Please sign in to comment.