Exception: JSONError

Inherits:
Exception
  • Object
show all
Defined in:
lib/ldapmodel/errors.rb

Direct Known Subclasses

BadCredentials, BadInput, InternalError, KerberosError, LdapError, NotFound, NotImplemented, Unauthorized, ValidationError

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (JSONError) initialize(message, meta = nil)

Returns a new instance of JSONError

Parameters:

  • message (String, Hash)

    Error message

Options Hash (message):

  • :user (Object)

    Error message that is displayed to requesting user

  • :mgs (Object)

    Internal error message for stack traces



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ldapmodel/errors.rb', line 8

def initialize(message, meta=nil)
  @meta = {}

  if message.kind_of?(Hash)
    @meta = message
    message = message[:msg] || message[:message] || message[:user]
  else
    @meta = meta || {}
  end

  super(message)
  @message = message

end

Instance Attribute Details

- (Object) meta

Returns the value of attribute meta



3
4
5
# File 'lib/ldapmodel/errors.rb', line 3

def meta
  @meta
end

Instance Method Details

- (Object) as_json



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ldapmodel/errors.rb', line 31

def as_json
  res = {
    :error => {
      :code => self.class.name.split(":").last
    }
  }
  if @meta[:user]
    res[:error][:message] = @meta[:user]
  end
  res
end

- (Object) headers



27
28
29
# File 'lib/ldapmodel/errors.rb', line 27

def headers
 {"Content-Type" => "application/json"}
end

- (Object) http_code



23
24
25
# File 'lib/ldapmodel/errors.rb', line 23

def http_code
  500
end

- (Object) to_json



43
44
45
# File 'lib/ldapmodel/errors.rb', line 43

def to_json
  as_json.to_json
end