Class: EasyTalk::ErrorFormatter::Jsonapi

Inherits:
Base
  • Object
show all
Defined in:
lib/easy_talk/error_formatter/jsonapi.rb

Overview

Formats validation errors according to the JSON:API specification.

JSON:API defines a standard error format with specific fields for status, source, title, detail, and optional code.

Examples:

Output

{
  "errors" => [
    {
      "status" => "422",
      "code" => "blank",
      "source" => { "pointer" => "/data/attributes/name" },
      "title" => "Invalid Attribute",
      "detail" => "Name can't be blank"
    }
  ]
}

See Also:

Constant Summary collapse

DEFAULT_STATUS =

Default values for JSON:API error fields

'422'
DEFAULT_TITLE =
'Invalid Attribute'

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from EasyTalk::ErrorFormatter::Base

Instance Method Details

#formatHash

Format the errors as a JSON:API error response.

Returns:

  • (Hash)

    The JSON:API error object with "errors" array



33
34
35
36
37
# File 'lib/easy_talk/error_formatter/jsonapi.rb', line 33

def format
  {
    'errors' => build_errors_array
  }
end