Exception: Eco::API::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/eco/api/error.rb,
lib/eco/api/error/handler.rb,
lib/eco/api/error/handlers.rb

Overview

To identify api server errors

Defined Under Namespace

Classes: CyclicSupervisor, EmailInvalid, EmailMissing, EmailTaken, ExternalIdTaken, Handler, Handlers, InternalServerError, InvalidObjectId, SchemaNotFound, SupervisorNotFound, Unclassified, UnknownErrorClass, UnknownPersonId, UnkownField

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, err_msg:, session: nil, entry: nil) ⇒ Error

Returns a new instance of Error.



133
134
135
136
137
138
139
140
# File 'lib/eco/api/error.rb', line 133

def initialize(msg = nil, err_msg:, session: nil, entry: nil)
  @msg     = msg
  @err_msg = err_msg
  @session = session
  @entry   = entry

  super(built_error)
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



131
132
133
# File 'lib/eco/api/error.rb', line 131

def entry
  @entry
end

#err_msgObject (readonly)

Returns the value of attribute err_msg.



131
132
133
# File 'lib/eco/api/error.rb', line 131

def err_msg
  @err_msg
end

#msgObject (readonly)

Returns the value of attribute msg.



131
132
133
# File 'lib/eco/api/error.rb', line 131

def msg
  @msg
end

#sessionObject (readonly)

Returns the value of attribute session.



131
132
133
# File 'lib/eco/api/error.rb', line 131

def session
  @session
end

Class Method Details

.descendants(direct: false) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/eco/api/error.rb', line 83

def descendants(direct: false)
  ObjectSpace.each_object(::Class).select do |klass|
    klass < self
  end.sort do |k1, k2|
    next -1 if k2 < k1
    next  1 if k1 < k2
    0
  end.tap do |siblings|
    siblings.delete(Unclassified)
    if direct
      siblings.reject! do |si|
        siblings.any? {|s| si < s}
      end
    end
  end
end

.descendants?(direct: false) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/eco/api/error.rb', line 100

def descendants?(direct: false)
  descendants(direct: direct).length > 0
end

.err_match?(err_msg) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/eco/api/error.rb', line 104

def err_match?(err_msg)
  err_msg =~ @match
end

.get_type(err_msg, first: true) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/eco/api/error.rb', line 108

def get_type(err_msg, first: true)
  type = nil
  descendants(direct: true).reverse.each do |klass|
    if klass.err_match?(err_msg)
      type = klass
      if klass.descendants?(direct: true)
        type = klass.get_type(err_msg, first: false) || type
      end
    end
  end
  return type unless first
  type || Unclassified
end

.known_err_class?(klass) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/eco/api/error.rb', line 122

def known_err_class?(klass)
  descendants.push(self).include?(klass)
end

.validate_err_class(klass) ⇒ Object

Raises:



126
127
128
# File 'lib/eco/api/error.rb', line 126

def validate_err_class(klass)
  raise UnknownErrorClass.new(klass: klass) unless known_err_class?(klass)
end

Instance Method Details

#built_errorObject



142
143
144
# File 'lib/eco/api/error.rb', line 142

def built_error
  str ||= msg
end