Exception: RocketPants::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rocket_pants/error.rb

Overview

Represents the standard error type as defined by the API. RocketPants::Error instances will be caught and automatically rendered as JSON by the controller during processing.

Direct Known Subclasses

InvalidResource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextHash

Gets the context for this error, defaulting to nil.

Returns:

  • (Hash)

    the context for this param.



51
52
53
# File 'lib/rocket_pants/error.rb', line 51

def context
  @context ||= {}
end

Class Method Details

.error_nameSymbol .error_name(value) ⇒ Object

Overloads:

  • .error_nameSymbol

    Returns the error name for this error class, defaulting to the class name underscorized minus _error.

    Returns:

    • (Symbol)

      the given errors name.

  • .error_name(value) ⇒ Object

    Sets the error name for the current class.

    Parameters:

    • the (#to_sym)

      name of this error.



15
16
17
18
19
20
21
# File 'lib/rocket_pants/error.rb', line 15

def self.error_name(value = nil)
  if value.nil?
    @name ||= name.underscore.split("/").last.sub(/_error$/, '').to_sym
  else
    @name = (value.presence && value.to_sym)
  end
end

.http_statusObject .http_status(value) ⇒ Object

Overloads:

  • .http_statusObject

    Returns the http status code of this error, defaulting to 400 (Bad Request).

  • .http_status(value) ⇒ Object

    Sets the http status code for this error to a given symbol / integer.

    Parameters:

    • value (String, Fixnum)

      value the new status code.



28
29
30
31
32
33
34
# File 'lib/rocket_pants/error.rb', line 28

def self.http_status(value = nil)
  if value.nil?
    @http_status ||= 400
  else
    @http_status = (value.presence && value)
  end
end

Instance Method Details

#error_nameObject

Gets the name of this error from the class.



37
38
39
# File 'lib/rocket_pants/error.rb', line 37

def error_name
  self.class.error_name
end

#http_statusObject

Gets the http status of this error from the class.



42
43
44
# File 'lib/rocket_pants/error.rb', line 42

def http_status
  self.class.http_status
end