class Temescal::Error

Constants

NOT_FOUND_ERRORS

Public Class Methods

new(exception) click to toggle source

Public: Instantiates a new Error.

exception - The raw exception being rescued.

Returns a new Error.

# File lib/temescal/error.rb, line 10
def initialize(exception)
  @exception = exception
end

Public Instance Methods

formatted() click to toggle source

Public: Formats the exception for logging.

Returns a String containing the relevant exception information to log via STDERR.

# File lib/temescal/error.rb, line 36
def formatted
  message = "\n#{@exception.class}: #{@exception.message}\n  "
  message << @exception.backtrace.join("\n  ")
  message << "\n\n"
end
ignore?() click to toggle source

Public: Determines whether an exception should be silenced.

Returns true if the error type is configured as an ignored error, false otherwise.

# File lib/temescal/error.rb, line 53
def ignore?
  configuration.ignored_errors.each do |error|
    return true if @exception.is_a? error
  end

  false
end
message() click to toggle source

Public: Determines whether to use a default message (as specified in the configuration) or the exception's message for the API response.

Returns a String that's either the default message or the exception's message.

# File lib/temescal/error.rb, line 19
def message
  configuration.default_message || @exception.message
end
status() click to toggle source

Public: Determines the proper error code for the exception.

Returns a Fixnum based on the exception's type and http_status attribute (if applicable), will return a generic 500 for all others.

# File lib/temescal/error.rb, line 27
def status
  return 404 if NOT_FOUND_ERRORS.include? @exception.class.to_s
  @exception.respond_to?(:http_status) ? @exception.http_status : 500
end
type() click to toggle source

Public: Gets the exception's type.

Returns a String representing the exception class name.

# File lib/temescal/error.rb, line 45
def type
  @exception.class.to_s
end

Private Instance Methods

configuration() click to toggle source

Private: Getter for Temescal configuration.

# File lib/temescal/error.rb, line 64
def configuration
  $_temescal_configuration
end