Class: ApiErrorHandler::Serializers::Json
- Inherits:
-
BaseSerializer
- Object
- BaseSerializer
- ApiErrorHandler::Serializers::Json
- Defined in:
- lib/api_error_handler/serializers/json.rb
Constant Summary
Constants inherited from BaseSerializer
BaseSerializer::DEFAULT_STATUS_CODE
Instance Method Summary collapse
- #render_format ⇒ Object
-
#serialize(options = {}) ⇒ Object
There is no official spec that governs this error response format so this serializer is just trying to impliment a simple response with sensible defaults.
Methods inherited from BaseSerializer
#initialize, #status_code, #title
Constructor Details
This class inherits a constructor from ApiErrorHandler::Serializers::BaseSerializer
Instance Method Details
#render_format ⇒ Object
29 30 31 |
# File 'lib/api_error_handler/serializers/json.rb', line 29 def render_format :json end |
#serialize(options = {}) ⇒ Object
There is no official spec that governs this error response format so this serializer is just trying to impliment a simple response with sensible defaults.
I borrowed heavily from Facebook's error response format since it seems to be a reasonable approach for a simple light-weight error response.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/api_error_handler/serializers/json.rb', line 15 def serialize( = {}) body = { error: { title: title, detail: @error., } } body[:error][:id] = [:error_id] if [:error_id] body[:error][:backtrace] = @error.backtrace if [:backtrace] body.to_json end |