Exception: Railsful::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/railsful/exceptions.rb

Overview

The base error for this gem.

Direct Known Subclasses

PaginationError, SortingError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(detail = nil, status = 400) ⇒ Error

Initializer.

Parameters:

  • detail (String) (defaults to: nil)

    The detailed message.

  • status (Integer) (defaults to: 400)

    The status code.



12
13
14
15
# File 'lib/railsful/exceptions.rb', line 12

def initialize(detail = nil, status = 400)
  @detail = detail
  @status = status
end

Instance Attribute Details

#detailObject (readonly)

Returns the value of attribute detail.



6
7
8
# File 'lib/railsful/exceptions.rb', line 6

def detail
  @detail
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/railsful/exceptions.rb', line 6

def status
  @status
end

Instance Method Details

#as_json(_options = nil) ⇒ Hash

Format the error as jsonapi wants it to.

Returns:

  • (Hash)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/railsful/exceptions.rb', line 20

def as_json(_options = nil)
  {
    errors: [
      {
        status: status,
        title: self.class.name.demodulize.underscore,
        detail: detail
      }
    ]
  }
end