Class: BatchApi::Errors::Base
- Inherits:
-
Object
- Object
- BatchApi::Errors::Base
- Defined in:
- lib/batch_api/errors/base.rb
Class Method Summary collapse
-
.expose_backtrace? ⇒ Boolean
Internal: whether the backtrace should be exposed in the response.
Instance Method Summary collapse
-
#body ⇒ Object
Public: the error details as a hash, which can be returned to clients as JSON.
-
#initialize(error) ⇒ Base
constructor
Public: create a new BatchError from a Rails error.
-
#render ⇒ Object
Public: turn the error body into a Rack-compatible body component.
-
#status_code ⇒ Object
Public: the status code to return for the given error.
Constructor Details
#initialize(error) ⇒ Base
Public: create a new BatchError from a Rails error.
8 9 10 |
# File 'lib/batch_api/errors/base.rb', line 8 def initialize(error) @error = error end |
Class Method Details
.expose_backtrace? ⇒ Boolean
Internal: whether the backtrace should be exposed in the response. Currently Rails-specific, needs to be generalized (to ENV)?
40 41 42 |
# File 'lib/batch_api/errors/base.rb', line 40 def self.expose_backtrace? !Rails.env.production? end |
Instance Method Details
#body ⇒ Object
Public: the error details as a hash, which can be returned to clients as JSON.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/batch_api/errors/base.rb', line 14 def body = if self.class.expose_backtrace? { message: @error., backtrace: @error.backtrace } else { message: @error. } end { error: } end |
#render ⇒ Object
Public: turn the error body into a Rack-compatible body component.
Returns: an Array with the error body represented as JSON.
29 30 31 |
# File 'lib/batch_api/errors/base.rb', line 29 def render [status_code, Middleware.content_type, [MultiJson.dump(body)]] end |
#status_code ⇒ Object
Public: the status code to return for the given error.
34 35 36 |
# File 'lib/batch_api/errors/base.rb', line 34 def status_code 500 end |