class PowerTrack::WithStatusPowerTrackError

Base class for PowerTrack errors with a precise status

Public Class Methods

build(status, message, body) click to toggle source

Factory method which returns an error instance based on a given status.

# File lib/powertrack/errors.rb, line 35
def self.build(status, message, body)
  @@status_to_error_class ||= Hash[*self.descendants.map { |desc|
    [ desc.new(nil, nil).status, desc ] }.flatten ]
  if @@status_to_error_class.key?(status)
    @@status_to_error_class[status].new(message, body)
  else
    # default to unknown status error
    UnknownStatusError.new(status, message, body)
  end
end