Class: StrongResources::ExceptionHandler

Inherits:
JsonapiErrorable::ExceptionHandler
  • Object
show all
Defined in:
lib/strong_resources/exception_handler.rb

Constant Summary collapse

SPLIT_REGEX =
/^Invalid parameter: ([\w]+)\W(.*)/

Instance Method Summary collapse

Instance Method Details

#error_payload(error) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/strong_resources/exception_handler.rb', line 5

def error_payload(error)
  message_parse = error.message.match(SPLIT_REGEX)

  attribute = message_parse[1]
  message = message_parse[2]
  error = {
    code:   'unprocessable_entity',
    status: '400',
    title: 'Malformed Attribute',
    detail: error.message,
    source: { pointer: "/data/attributes/#{attribute}" },
    meta:   {
      attribute: attribute,
      message: message
    }
  }

  {
    "errors" => [error]
  }
end

#log?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/strong_resources/exception_handler.rb', line 31

def log?
  false
end

#status_code(_) ⇒ Object



27
28
29
# File 'lib/strong_resources/exception_handler.rb', line 27

def status_code(_)
  400
end