Class: Apia::Error

Inherits:
Object
  • Object
show all
Extended by:
Defineable
Defined in:
lib/apia/error.rb

Overview

An Error represents a specific failure that can be raised by any action within the API.

An error can specify a ‘code` which is textual description of the error which will be returned to the user.

An HTTP status code can be provided which will be sent to the user if the error is incurred. If no HTTP status code is provided, the a 500 error code will be used.

You can also define an array of additional fields that can included when the error is raised. This works in the same way as any type and an object implementing those methods should be provided when the error is raised.

Direct Known Subclasses

ScopeNotGrantedError

Class Method Summary collapse

Methods included from Defineable

create, inspect, method_missing, name, respond_to_missing?

Class Method Details

.collate_objects(set) ⇒ void

This method returns an undefined value.

Collate all objects that this error references and add them to the given object set

Parameters:



43
44
45
46
47
# File 'lib/apia/error.rb', line 43

def collate_objects(set)
  definition.fields.each_value do |field|
    set.add_object(field.type.klass) if field.type.usable_for_field?
  end
end

.definitionApia::Definitions::Error

Return the definition object for errors



34
35
36
# File 'lib/apia/error.rb', line 34

def definition
  @definition ||= Definitions::Error.new(Helpers.class_name_to_id(name))
end

.exception(fields = {}) ⇒ ErrorExceptionError

Return an exception that should be raised to represent this error when it is actually invoked

Parameters:

  • fields (Hash) (defaults to: {})

Returns:



54
55
56
# File 'lib/apia/error.rb', line 54

def exception(fields = {})
  ErrorExceptionError.new(self, fields)
end