Skip to content

Instantly share code, notes, and snippets.

@SunDi3yansyah
Last active April 30, 2019 18:10
Show Gist options
  • Save SunDi3yansyah/57bc04991af0281ba30675270ec5fd7b to your computer and use it in GitHub Desktop.
Save SunDi3yansyah/57bc04991af0281ba30675270ec5fd7b to your computer and use it in GitHub Desktop.
Exception Handler in Rails => https://git.io/fjZIW
module ExceptionHandler
extend ActiveSupport::Concern
included do
rescue_from ActionController::Base,
ActionController::API,
# ActionController::Middleware,
ActionController::Streaming,
ActionController::LogSubscriber,
ActionController::TestCase,
ActionController::Railties,
ActionController::Railtie,
ActionController::MiddlewareStack,
ActionController::Cookies,
ActionController::ContentSecurityPolicy,
ActionController::Flash,
ActionController::Parameters,
ActionController::ConditionalGet,
ActionController::Head,
ActionController::Helpers,
ActionController::Metal,
ActionController::Renderer,
ActionController::FormBuilder,
ActionController::Caching,
ActionController::DataStreaming,
ActionController::EtagWithTemplateDigest,
ActionController::EtagWithFlash,
ActionController::ForceSSL,
ActionController::HttpAuthentication,
ActionController::BasicImplicitRender,
ActionController::ImplicitRender,
ActionController::Instrumentation,
ActionController::MimeResponds,
ActionController::ParamsWrapper,
ActionController::Redirecting,
ActionController::Renderers,
ActionController::Rendering,
ActionController::RequestForgeryProtection,
ActionController::Rescue,
ActionController::StrongParameters,
ActionController::ParameterEncoding,
ActionController::Testing,
ActionController::UrlFor,
ActionController::ApiRendering,
ActionController::TemplateAssertions,
ActionController::Live,
ActionController::ParameterMissing,
ActionController::UnpermittedParameters,
ActionController::UnfilteredParameters,
ActionController::BadRequest,
ActionController::MethodNotAllowed,
ActionController::NotImplemented,
ActionController::RoutingError,
ActionController::UrlGenerationError,
ActionController::ActionControllerError,
ActionController::RenderError,
ActionController::MissingFile,
ActionController::SessionOverflowError,
ActionController::UnknownHttpMethod,
ActionController::UnknownFormat,
ActionController::MissingRenderer,
ActionController::InvalidAuthenticityToken,
ActionController::InvalidCrossOriginRequest do |e|
api({ message: e.message }, 500)
end
rescue_from ActiveRecord::Migrator,
ActiveRecord::NoDatabaseError,
ActiveRecord::QueryCache,
ActiveRecord::MigrationContext,
ActiveRecord::LogSubscriber,
ActiveRecord::InternalMetadata,
ActiveRecord::RecordInvalid,
ActiveRecord::RuntimeRegistry,
ActiveRecord::Schema,
ActiveRecord::SchemaDumper,
ActiveRecord::SchemaMigration,
ActiveRecord::StatementCache,
ActiveRecord::ActiveRecordError,
ActiveRecord::ConnectionNotEstablished,
ActiveRecord::Relation,
ActiveRecord::AssociationRelation,
ActiveRecord::Result,
ActiveRecord::PredicateBuilder,
ActiveRecord::TableMetadata,
ActiveRecord::DuplicateMigrationVersionError,
ActiveRecord::DuplicateMigrationNameError,
ActiveRecord::MigrationError,
ActiveRecord::IrreversibleMigration,
ActiveRecord::PendingMigrationError,
ActiveRecord::ConfigurationError,
ActiveRecord::IllegalMigrationNameError,
ActiveRecord::NoEnvironmentInSchemaError,
ActiveRecord::ConcurrentMigrationError,
ActiveRecord::EnvironmentMismatchError,
ActiveRecord::UnknownMigrationVersionError,
ActiveRecord::ProtectedEnvironmentError,
ActiveRecord::Railtie,
ActiveRecord::ExplainRegistry,
ActiveRecord::HasManyThroughAssociationPointlessSourceTypeError,
ActiveRecord::AssociationNotFoundError,
ActiveRecord::InverseOfAssociationNotFoundError,
ActiveRecord::StatementInvalid,
ActiveRecord::ExplainSubscriber,
ActiveRecord::HasManyThroughOrderError,
ActiveRecord::ThroughCantAssociateThroughHasOneOrManyReflection,
ActiveRecord::HasManyThroughAssociationPolymorphicSourceError,
ActiveRecord::AmbiguousSourceReflectionForThroughAssociation,
ActiveRecord::HasManyThroughAssociationPolymorphicThroughError,
ActiveRecord::ConnectionTimeoutError,
ActiveRecord::ExclusiveConnectionTimeoutError,
ActiveRecord::HasOneAssociationPolymorphicThroughError,
ActiveRecord::HasManyThroughSourceAssociationNotFoundError,
ActiveRecord::HasManyThroughNestedAssociationsAreReadonly,
ActiveRecord::HasOneThroughNestedAssociationsAreReadonly,
ActiveRecord::HasManyThroughAssociationNotFoundError,
ActiveRecord::DeleteRestrictionError,
ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection,
ActiveRecord::HasOneThroughCantAssociateThroughCollection,
ActiveRecord::ThroughNestedAssociationsAreReadonly,
ActiveRecord::EagerLoadPolymorphicError,
ActiveRecord::HasOneThroughCantAssociateThroughHasOneOrManyReflection,
ActiveRecord::MigrationProxy,
ActiveRecord::NullMigration,
ActiveRecord::SuppressorRegistry,
ActiveRecord::Rollback,
ActiveRecord::TransactionIsolationError,
ActiveRecord::DangerousAttributeError,
ActiveRecord::UnknownAttributeReference,
ActiveRecord::UnknownAttributeError,
ActiveRecord::SubclassNotFound,
ActiveRecord::AssociationTypeMismatch,
ActiveRecord::SerializationTypeMismatch,
ActiveRecord::AdapterNotSpecified,
ActiveRecord::AdapterNotFound,
ActiveRecord::RecordNotFound,
ActiveRecord::RecordNotSaved,
ActiveRecord::RecordNotDestroyed,
ActiveRecord::WrappedDatabaseException,
ActiveRecord::RecordNotUnique,
ActiveRecord::InvalidForeignKey,
ActiveRecord::MismatchedForeignKey,
ActiveRecord::NotNullViolation,
ActiveRecord::ValueTooLong,
ActiveRecord::PreparedStatementInvalid,
ActiveRecord::PreparedStatementCacheExpired,
ActiveRecord::StaleObjectError,
ActiveRecord::ReadOnlyRecord,
ActiveRecord::AttributeAssignmentError,
ActiveRecord::MultiparameterAssignmentErrors,
ActiveRecord::UnknownPrimaryKey,
ActiveRecord::ImmutableRelation,
ActiveRecord::TransactionRollbackError,
ActiveRecord::SerializationFailure,
ActiveRecord::Deadlocked,
ActiveRecord::IrreversibleOrderError,
ActiveRecord::LockWaitTimeout,
ActiveRecord::StatementTimeout,
ActiveRecord::QueryCanceled,
ActiveRecord::Base,
ActiveRecord::TypeConflictError,
ActiveRecord::RangeError,
ActiveRecord::Migration do |e|
api({ message: e.message }, 500)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment