Class: RequestErrorSerializer

Inherits:
Object
  • Object
show all
Includes:
JSONAPI::ErrorSerializer
Defined in:
lib/act_as_jsonapi/request_error_serializer.rb

Overview

Request Error Serializer Provides additional information about problems encountered while performing a request operation. The possible attributes are:

+id+      a unique identifier for this particular occurrence of the problem.
+title+   a short, human-readable summary of the problem
+detail+  a human-readable explanation specific to this occurrence of the problem
+code+    an application-specific error code, expressed as a string value.
+status+  the HTTP status code applicable to this problem, expressed as a string value.

Class Method Summary collapse

Class Method Details

.from_active_model_errors(errors) ⇒ Object

This is a generic active model error serializer that transform an ActiveModel::Errors object to a JSON:API compliant error serializer



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/act_as_jsonapi/request_error_serializer.rb', line 24

def self.from_active_model_errors(errors)
  error_array = errors.full_messages.map do |error_msg|
    {
      id: SecureRandom.uuid,
      title: error_msg,
      detail: error_msg,
      code: 'CLIENT400',
      status: '400',
      meta: {error: error_msg}
    }
  end

  new(error_array)
end