0
내가 태그 로그에 대한 내 자신의 Exception
를 구축하기 위해 노력하고있어 :레일 - 사용자 정의 예외 (오류)
raise Exceptions::SecurityException "Something security related happened.
module Exceptions
class GeneralException < StandardError
LOGGER_NAME = 'Base'
def initialize(message)
@logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
@logger.tagged(get_logger_name) { @logger.error message }
@message = message
end
def get_logger_name
self.class::LOGGER_NAME
end
end
class InvalidDataException < GeneralException; end
class SecurityException < GeneralException
LOGGER_NAME = 'Security'
end
class ElasticSearchException < GeneralException
LOGGER_NAME = 'Elastic'
end
end
을
문제는 내가이를 호출 할 때 내가 얻을 수 있습니다 :
NoMethodError: undefined method 'SecurityException' for Exceptions:Module
어떤 생각을 올바르게이 오류를 제기하는 방법?
에, SecurityException가없는 방법입니다. 그것은 수업입니다. 먼저 메시지를 인스턴스화하고 메시지를 전달해야합니다. – jemonsanto