Skip to content

Instantly share code, notes, and snippets.

@trevorrowe
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevorrowe/8162733833c90491a9b3 to your computer and use it in GitHub Desktop.
Save trevorrowe/8162733833c90491a9b3 to your computer and use it in GitHub Desktop.
Plugin that conditionally raises response errors
class ConditionalRaisePlugin < Seahorse::Client::Plugin
class Handler < Seahorse::Client::Handler
def call(context)
response = @handler.call(context)
conditional_raise(response.error, context.config.errors_to_ignore)
response
end
private
def conditional_raise(error, ignored)
raise error unless ignored.any? { |error_class| error_class === error }
end
end
option(:errors_to_ignore, [])
handler(Handler, step: :validate, priority: 95)
end
# replace default plugin
Aws::DynamoDB::Client.remove_plugin(Seahorse::Client::Plugins::RaiseResponseErrors)
Aws::DynamoDB::Client.add_plugin(ConditionalRaisePlugin)
# create a white-list of error types that should not be raised
ddb = Aws::DynamoDB::Client.new(errors_to_ignore: [
Aws::DynamoDB::Errors::ResourceNotFoundException,
])
resp = ddb.describe_table(table_name: 'no-such-table')
resp.error
#=> #<Aws::DynamoDB::Errors::ResourceNotFoundException: Requested resource not found: Table: no-such-table not found>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment