class Pragma::Operation::Error

A generic error entity to hold error information for HTTP responses.

This format is not mandatory, but recommended for consistency and convenience.

Attributes

error_message[R]

@!attribute [r] error_type

@return [Symbol|String] a machine-readable error type

@!attribute [r] error_message

@return [String] a human-readable error message

@!attribute [r] meta

@return [Hash] metadata about the error
error_type[R]

@!attribute [r] error_type

@return [Symbol|String] a machine-readable error type

@!attribute [r] error_message

@return [String] a human-readable error message

@!attribute [r] meta

@return [Hash] metadata about the error
meta[R]

@!attribute [r] error_type

@return [Symbol|String] a machine-readable error type

@!attribute [r] error_message

@return [String] a human-readable error message

@!attribute [r] meta

@return [Hash] metadata about the error

Public Class Methods

new(error_type:, error_message:, meta: {}) click to toggle source

Creates a new error entity.

@param error_type [Symbol|String] a machine-readable error type @param error_message [String] a human-readable error message @param meta [Hash] metadata about the error

# File lib/pragma/operation/error.rb, line 24
def initialize(error_type:, error_message:, meta: {})
  @error_type = error_type
  @error_message = error_message
  @meta = meta
end

Public Instance Methods

as_json(*) click to toggle source

Converts the entity to a hash ready to be dumped as JSON.

@return [Hash]

# File lib/pragma/operation/error.rb, line 33
def as_json(*)
  {
    error_type: error_type,
    error_message: error_message,
    meta: meta
  }
end
to_json() click to toggle source

Dumps the JSON representation as a JSON string.

@return [String]

@see as_json

# File lib/pragma/operation/error.rb, line 46
def to_json
  JSON.dump as_json
end