-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'decaf' into decaf_endpoints
- Loading branch information
Showing
8 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
gems/smithy-client/lib/smithy-client/plugins/raise_response_errors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Smithy | ||
module Client | ||
module Plugins | ||
# @api private | ||
class RaiseResponseErrors < Plugin | ||
option( | ||
:raise_response_errors, | ||
default: true, | ||
doc_type: 'Boolean', | ||
docstring: <<~DOCS) | ||
When `true`, response errors are raised. When `false`, the error is placed on the | ||
output in the {Smithy::Client::Output#error error accessor}. | ||
DOCS | ||
|
||
# @api private | ||
class Handler < Client::Handler | ||
def call(context) | ||
output = @handler.call(context) | ||
raise output.error if output.error | ||
|
||
output | ||
end | ||
end | ||
|
||
def add_handlers(handlers, config) | ||
handlers.add(Handler, step: :validate, priority: 95) if config.raise_response_errors | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
gems/smithy-client/spec/smithy-client/plugins/raise_response_errors_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module Smithy | ||
module Client | ||
module Plugins | ||
describe RaiseResponseErrors do | ||
let(:client_class) do | ||
api = API.new | ||
api.add_operation(:operation_name, Operation.new) | ||
client_class = Class.new(Client::Base) | ||
client_class.api = api | ||
client_class.clear_plugins | ||
client_class.add_plugin(RaiseResponseErrors) | ||
client_class.add_plugin(DummySendPlugin) | ||
client_class | ||
end | ||
|
||
it 'adds a :raise_response_errors option to config' do | ||
client = client_class.new(raise_response_errors: false) | ||
expect(client.config.raise_response_errors).to be(false) | ||
end | ||
|
||
it 'defaults :raise_response_errors to true' do | ||
client = client_class.new | ||
expect(client.config.raise_response_errors).to be(true) | ||
end | ||
|
||
it 'does not add the handler if :raise_response_errors is false' do | ||
client = client_class.new(raise_response_errors: false) | ||
expect(client.handlers).not_to include(Handler) | ||
end | ||
|
||
it 'returns output' do | ||
client = client_class.new | ||
output = client.operation_name | ||
expect(output).to be_kind_of(Output) | ||
end | ||
|
||
it 'raises the response error when :raise_response_errors is true' do | ||
error = StandardError.new('msg') | ||
client = client_class.new(response_error: error) | ||
expect { client.operation_name }.to raise_error(error) | ||
end | ||
|
||
it 'puts the error on the output when :raise_response_errors is false' do | ||
error = StandardError.new('msg') | ||
client = client_class.new( | ||
raise_response_errors: false, | ||
response_error: error | ||
) | ||
output = client.operation_name | ||
expect(output.error).to be(error) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters