Exception: Barion::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/barion.rb

Overview

Generic error class for Barion module

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Error

Creates a new instance of the Barion::Error class. It can hold nested errors.

Parameters:

  • params (Hash)

    a hash containing the error data

Options Hash (params):

  • :Title (String)

    the title of the error

  • :ErrorCode (Integer)

    the error code

  • :HappenedAt (String)

    when the error happened in ISO 8601 format

  • :AuthData (String)

    authentication data

  • :Endpoint (String)

    the endpoint where the error happened

  • :Errors (Array<Hash>)

    the errors that happened

  • :Description (String)

    the description of the error



316
317
318
319
320
321
322
323
324
325
# File 'lib/barion.rb', line 316

def initialize(params)
  @title = params[:Title]
  @error_code = params[:ErrorCode]
  @happened_at = params[:HappenedAt]
  @auth_data = params[:AuthData]
  @endpoint = params[:Endpoint]
  @errors = Array(params[:Errors]).map { |e| Barion::Error.new(e) } if params.key? :Errors
  @description = params[:Description]
  super(@description)
end

Instance Attribute Details

#auth_dataObject (readonly)

Returns the value of attribute auth_data.



304
305
306
# File 'lib/barion.rb', line 304

def auth_data
  @auth_data
end

#descriptionObject (readonly)

Returns the value of attribute description.



304
305
306
# File 'lib/barion.rb', line 304

def description
  @description
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



304
305
306
# File 'lib/barion.rb', line 304

def endpoint
  @endpoint
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



304
305
306
# File 'lib/barion.rb', line 304

def error_code
  @error_code
end

#errorsObject (readonly)

Returns the value of attribute errors.



304
305
306
# File 'lib/barion.rb', line 304

def errors
  @errors
end

#happened_atObject (readonly)

Returns the value of attribute happened_at.



304
305
306
# File 'lib/barion.rb', line 304

def happened_at
  @happened_at
end

#titleObject (readonly)

Returns the value of attribute title.



304
305
306
# File 'lib/barion.rb', line 304

def title
  @title
end

Instance Method Details

#all_errorsString

Returns all errors that happened in the request in a single string

Returns:

  • (String)

    all errors that happened in the request



330
331
332
# File 'lib/barion.rb', line 330

def all_errors
  Array(@errors).map(&:message).join("\n")
end