Last Updated: February 25, 2016
·
793
· mbillard

Throw the right Error

Here's an (incomplete) list of Error classes that you might want to throw that are available in Rails:

ActionController::ActionControllerError
ActionController::RedirectBackError
ActionController::RenderError
ActionController::RoutingError
ActionController::SessionOverflowError
ActionDispatch::RemoteIp::IpSpoofAttackError
ActionDispatch::Session::SessionRestoreError
ActionView::Helpers::NumberHelper::InvalidNumberError
ActiveModel::MassAssignmentSecurity::Error
ActiveModel::MissingAttributeError
ActiveRecord::ActiveRecordError
ActiveRecord::AttributeAssignmentError
ActiveRecord::ConfigurationError
ActiveRecord::ConnectionTimeoutError
ActiveRecord::DangerousAttributeError
ActiveRecord::DeleteRestrictionError
ActiveRecord::DuplicateMigrationNameError
ActiveRecord::DuplicateMigrationVersionError
ActiveRecord::EagerLoadPolymorphicError
ActiveRecord::HasManyThroughAssociationNotFoundError
ActiveRecord::HasManyThroughAssociationPointlessSourceTypeError
ActiveRecord::HasManyThroughAssociationPolymorphicSourceError
ActiveRecord::HasManyThroughAssociationPolymorphicThroughError
ActiveRecord::HasManyThroughSourceAssociationNotFoundError
ActiveRecord::IllegalMigrationNameError
ActiveRecord::InverseOfAssociationNotFoundError
ActiveRecord::StaleObjectError
ActiveRecord::Transactions::TransactionError
ActiveRecord::UnknownAttributeError
ActiveRecord::UnknownMigrationVersionError
ActiveResource::ClientError
ActiveResource::ConnectionError
ActiveResource::SSLError
ActiveResource::ServerError
ActiveResource::TimeoutError
ActiveSupport::JSON::Encoding::CircularReferenceError
ActiveSupport::SafeBuffer::SafeConcatError
ActiveSupport::Testing::RemoteError
ArgumentError
EOFError
EncodingError
FiberError
FloatDomainError
IOError
IndexError
KeyError
LoadError
NameError
NoMemoryError
NoMethodError
NotImplementedError
RangeError
RegexpError
RuntimeError
ScriptError
SecurityError
SocketError
StandardError
StateMachine::Error
StringScanner::Error
SyntaxError
SystemCallError
SystemStackError
ThreadError
Timeout::Error
TypeError
URI::BadURIError
URI::Error
URI::InvalidComponentError
URI::InvalidURIError

If any of them aren't available, let me know, I extracted the list from my environment and a few might come from gems.