Class: Cuprum::Rails::Serializers::Json::ErrorSerializer

Inherits:
BaseSerializer
  • Object
show all
Defined in:
lib/cuprum/rails/serializers/json/error_serializer.rb

Overview

Converts a Cuprum::Error to JSON using the #as_json method.

Instance Method Summary collapse

Methods inherited from BaseSerializer

instance

Instance Method Details

#call(error, **_) ⇒ Hash

Converts the Cuprum error to JSON.

Calls and returns the #as_json method of the error.

Parameters:

  • error (Cuprum::Error)

    The error to convert to JSON.

Returns:

  • (Hash)

    a JSON-compatible representation of the error.



16
17
18
19
20
21
22
# File 'lib/cuprum/rails/serializers/json/error_serializer.rb', line 16

def call(error, **_)
  unless error.is_a?(Cuprum::Error)
    raise ArgumentError, 'object must be a Cuprum::Error'
  end

  error.as_json
end