Exception: OAI::Exception

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/oai/exception.rb

Overview

Standard error responses for problems serving OAI content. These messages will be wrapped in an XML response to the client.

Constant Summary collapse

CODE =
nil
MESSAGE =
nil
@@codes =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, code = nil) ⇒ Exception

Returns a new instance of Exception.



22
23
24
25
# File 'lib/oai/exception.rb', line 22

def initialize(message = nil, code = nil)
  super(message || self.class::MESSAGE)
  @code = code || self.class::CODE
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



10
11
12
# File 'lib/oai/exception.rb', line 10

def code
  @code
end

Class Method Details

.for(message: nil, code: nil) ⇒ Object



18
19
20
# File 'lib/oai/exception.rb', line 18

def self.for(message: nil, code: nil)
  @@codes.fetch(code, Exception).new(message)
end

.register_exception_code(code, exception_class) ⇒ Object



14
15
16
# File 'lib/oai/exception.rb', line 14

def self.register_exception_code(code, exception_class)
  @@codes[code] = exception_class if exception_class.superclass == OAI::Exception
end