class Noise::PublicError
Base class for all api level errors
Attributes
code[R]
options[R]
Public Class Methods
new(code, message_or_options = nil)
click to toggle source
@overload new(code, message)
Instantiate error with given code and message @param code [Symbol] @param message_or_options [String]
@overload new(code, options)
Instantiate error with given code and options. Options would be passed to I18n key @param code [Symbol] @param message_or_options [Hash{Symbol => any}] @example Given the following I18n key exists: noise: public_error: unknown_fields: "Server does not know how to recognize these fields: %{fields}" To render error with this message: PublicError.new(:unknown_fields, fields: 'nickname, phone')
# File lib/noise/public_error.rb, line 34 def initialize(code, message_or_options = nil) @code = code.to_sym case message_or_options when Hash @options = message_or_options @message = nil else @options = {} @message = message_or_options end end
register_as(status, severity:)
click to toggle source
@param status [Symbol, Integer]
@see http://apidock.com/rails/ActionController/Base/render#254-List-of-status-codes-and-their-symbols
@param severity [Symbol, Integer]
@see `Noise::Notification::SEVERITIES`
@example
GoneError.register_as(:gone, :info)
# File lib/noise/public_error.rb, line 71 def register_as(status, severity:) Noise::ExceptionResponder.register(name, status: status) Noise::Notification.register(name, severity: severity) end
Public Instance Methods
inspect()
click to toggle source
@return [String]
# File lib/noise/public_error.rb, line 52 def inspect "#<#{self.class}: #{message}>" end
message()
click to toggle source
@return [String]
# File lib/noise/public_error.rb, line 47 def message @message.presence || I18n.t("noise.#{self.class.name.demodulize.underscore}.#{@code}", @options) end
responder_class()
click to toggle source
@return [ExceptionResponder] @api private
# File lib/noise/public_error.rb, line 58 def responder_class ExceptionResponder end