AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Class: Aws::SessionStore::DynamoDB::Errors::DefaultHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/aws/session_store/dynamo_db/errors/default_handler.rb

Overview

This class handles errors raised from DynamoDB.

Constant Summary collapse

HARD_ERRORS =

Array of errors that will always be passed up the Rack stack.

[
  Aws::DynamoDB::Errors::ResourceNotFoundException,
  Aws::DynamoDB::Errors::ConditionalCheckFailedException,
  Aws::SessionStore::DynamoDB::MissingSecretKeyError,
  Aws::SessionStore::DynamoDB::LockWaitTimeoutError
]

Instance Method Summary collapse

Constructor Details

#initialize(raise_errors) ⇒ DefaultHandler

Determines behavior of DefaultErrorHandler

Parameters:

  • raise_errors (true)

    Pass all errors up the Rack stack.



28
29
30
# File 'lib/aws/session_store/dynamo_db/errors/default_handler.rb', line 28

def initialize(raise_errors)
  @raise_errors = raise_errors
end

Instance Method Details

#errors_string(error) ⇒ Object

Returns string to be placed in error stream



49
50
51
52
53
54
55
# File 'lib/aws/session_store/dynamo_db/errors/default_handler.rb', line 49

def errors_string(error)
  str = []
  str << "Exception occurred: #{error.message}"
  str << "Stack trace:"
  str += error.backtrace.map {|l| "  " + l }
  str.join("\n")
end

#handle_error(error, env = {}) ⇒ Object

Raises HARD_ERRORS up the Rack stack. Places all other errors in Racks error stream.



34
35
36
37
38
39
40
41
# File 'lib/aws/session_store/dynamo_db/errors/default_handler.rb', line 34

def handle_error(error, env = {})
  if HARD_ERRORS.include?(error.class) || @raise_errors
    raise error
  else
    store_error(error, env)
    false
  end
end

#store_error(error, env = {}) ⇒ Object

Sends error to error stream



44
45
46
# File 'lib/aws/session_store/dynamo_db/errors/default_handler.rb', line 44

def store_error(error, env = {})
  env["rack.errors"].puts(errors_string(error)) if env
end