aws-sdk 1.6.3 → 1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/aws/api_config/AutoScaling-2011-01-01.yml +1 -0
- data/lib/aws/api_config/CloudFormation-2010-05-15.yml +1 -0
- data/lib/aws/api_config/CloudFront-2012-05-05.yml +2137 -0
- data/lib/aws/api_config/CloudWatch-2010-08-01.yml +9 -0
- data/lib/aws/api_config/DynamoDB-2011-12-05.yml +616 -0
- data/lib/aws/api_config/EC2-2012-07-20.yml +1 -0
- data/lib/aws/api_config/ELB-2012-06-01.yml +1 -0
- data/lib/aws/api_config/EMR-2009-03-31.yml +1 -0
- data/lib/aws/api_config/IAM-2010-05-08.yml +1 -0
- data/lib/aws/api_config/Route53-2012-02-29.yml +350 -349
- data/lib/aws/api_config/SNS-2010-03-31.yml +1 -0
- data/lib/aws/api_config/SQS-2011-10-01.yml +1 -0
- data/lib/aws/api_config/STS-2011-06-15.yml +1 -0
- data/lib/aws/api_config/SimpleDB-2009-04-15.yml +1 -0
- data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +62 -0
- data/lib/aws/api_config/SimpleWorkflow-2012-01-25.yml +1637 -0
- data/lib/aws/auto_scaling/client.rb +2 -37
- data/lib/aws/cloud_formation/client.rb +2 -17
- data/lib/aws/cloud_watch/client.rb +2 -15
- data/lib/aws/core.rb +24 -4
- data/lib/aws/core/client.rb +115 -46
- data/lib/aws/core/configuration.rb +6 -0
- data/lib/aws/core/credential_providers.rb +1 -0
- data/lib/aws/core/http/curb_handler.rb +3 -3
- data/lib/aws/core/http/httparty_handler.rb +15 -15
- data/lib/aws/core/json_client.rb +19 -77
- data/lib/aws/core/json_error_parser.rb +25 -0
- data/lib/aws/core/json_request_builder.rb +34 -0
- data/lib/aws/core/json_response_parser.rb +81 -0
- data/lib/aws/core/log_formatter.rb +25 -25
- data/lib/aws/core/option_grammar.rb +123 -115
- data/lib/aws/core/options/xml_serializer.rb +13 -9
- data/lib/aws/core/query_client.rb +13 -104
- data/lib/aws/core/query_error_parser.rb +24 -0
- data/lib/aws/core/query_request_builder.rb +47 -0
- data/lib/aws/core/query_response_parser.rb +35 -0
- data/lib/aws/core/rest_client.rb +13 -62
- data/lib/aws/core/rest_error_parser.rb +24 -0
- data/lib/aws/core/rest_request_builder.rb +124 -0
- data/lib/aws/core/rest_response_parser.rb +48 -0
- data/lib/aws/core/xml/parser.rb +2 -2
- data/lib/aws/core/xml/root_frame.rb +1 -1
- data/lib/aws/dynamo_db.rb +10 -9
- data/lib/aws/dynamo_db/binary.rb +35 -0
- data/lib/aws/dynamo_db/client.rb +103 -20
- data/lib/aws/dynamo_db/config.rb +2 -0
- data/lib/aws/dynamo_db/item.rb +3 -0
- data/lib/aws/dynamo_db/primary_key_element.rb +2 -1
- data/lib/aws/dynamo_db/table.rb +32 -36
- data/lib/aws/dynamo_db/table_collection.rb +13 -13
- data/lib/aws/dynamo_db/types.rb +34 -9
- data/lib/aws/ec2/client.rb +884 -344
- data/lib/aws/ec2/filtered_collection.rb +2 -3
- data/lib/aws/elb/client.rb +59 -45
- data/lib/aws/emr/client.rb +2 -11
- data/lib/aws/iam/client.rb +9 -80
- data/lib/aws/record/hash_model/attributes.rb +28 -13
- data/lib/aws/route_53/client.rb +6 -16
- data/lib/aws/s3/client.rb +2 -1
- data/lib/aws/s3/encryption_utils.rb +2 -7
- data/lib/aws/s3/s3_object.rb +5 -0
- data/lib/aws/simple_db/client.rb +2 -14
- data/lib/aws/simple_email_service/client.rb +35 -19
- data/lib/aws/simple_email_service/identity.rb +49 -10
- data/lib/aws/simple_email_service/identity_collection.rb +4 -4
- data/lib/aws/simple_workflow/client.rb +2 -38
- data/lib/aws/sns/client.rb +2 -19
- data/lib/aws/sqs/client.rb +2 -19
- data/lib/aws/sqs/errors.rb +5 -5
- data/lib/aws/sts/client.rb +2 -6
- metadata +14 -5
- data/lib/aws/core/rest_client/input_handler.rb +0 -145
- data/lib/aws/core/rest_client/output_handler.rb +0 -53
data/lib/aws/core.rb
CHANGED
@@ -62,14 +62,14 @@ require 'aws/core/autoloader'
|
|
62
62
|
# config/initializers/aws-sdk.rb
|
63
63
|
#
|
64
64
|
# Optionally you can create a Yaml configuration file at
|
65
|
-
# RAILS_ROOT/config/aws.
|
65
|
+
# RAILS_ROOT/config/aws.yml; This should be formatted in the same manor
|
66
66
|
# as the default RAILS_ROOT/config/database.yml file (one section for
|
67
67
|
# each Rails environment).
|
68
68
|
#
|
69
69
|
module AWS
|
70
70
|
|
71
71
|
# Current version of the AWS SDK for Ruby
|
72
|
-
VERSION = "1.6.
|
72
|
+
VERSION = "1.6.4"
|
73
73
|
|
74
74
|
register_autoloads(self) do
|
75
75
|
autoload :Errors, 'errors'
|
@@ -78,6 +78,7 @@ module AWS
|
|
78
78
|
module Core
|
79
79
|
|
80
80
|
AWS.register_autoloads(self) do
|
81
|
+
|
81
82
|
autoload :AsyncHandle, 'async_handle'
|
82
83
|
autoload :Cacheable, 'cacheable'
|
83
84
|
autoload :Client, 'client'
|
@@ -87,9 +88,11 @@ module AWS
|
|
87
88
|
autoload :Data, 'data'
|
88
89
|
autoload :IndifferentHash, 'indifferent_hash'
|
89
90
|
autoload :Inflection, 'inflection'
|
91
|
+
|
90
92
|
autoload :JSONClient, 'json_client'
|
91
|
-
autoload :
|
92
|
-
autoload :
|
93
|
+
autoload :JSONRequestBuilder, 'json_request_builder'
|
94
|
+
autoload :JSONResponseParser, 'json_response_parser'
|
95
|
+
|
93
96
|
autoload :LazyErrorClasses, 'lazy_error_classes'
|
94
97
|
autoload :LogFormatter, 'log_formatter'
|
95
98
|
autoload :MetaUtils, 'meta_utils'
|
@@ -98,13 +101,24 @@ module AWS
|
|
98
101
|
autoload :OptionGrammar, 'option_grammar'
|
99
102
|
autoload :PageResult, 'page_result'
|
100
103
|
autoload :Policy, 'policy'
|
104
|
+
|
105
|
+
autoload :QueryClient, 'query_client'
|
106
|
+
autoload :QueryRequestBuilder, 'query_request_builder'
|
107
|
+
autoload :QueryResponseParser, 'query_response_parser'
|
108
|
+
|
101
109
|
autoload :Resource, 'resource'
|
102
110
|
autoload :ResourceCache, 'resource_cache'
|
103
111
|
autoload :Response, 'response'
|
104
112
|
autoload :ResponseCache, 'response_cache'
|
113
|
+
|
114
|
+
autoload :RESTClient, 'rest_client'
|
115
|
+
autoload :RESTRequestBuilder, 'rest_request_builder'
|
116
|
+
autoload :RESTResponseParser, 'rest_response_parser'
|
117
|
+
|
105
118
|
autoload :ServiceInterface, 'service_interface'
|
106
119
|
autoload :Signer, 'signer'
|
107
120
|
autoload :UriEscape, 'uri_escape'
|
121
|
+
|
108
122
|
end
|
109
123
|
|
110
124
|
module Options
|
@@ -209,6 +223,12 @@ module AWS
|
|
209
223
|
# @option options [String] :cloud_formation_endpoint ('cloudformation.us-east-1.amazonaws.com')
|
210
224
|
# The service endpoint for AWS CloudFormation.
|
211
225
|
#
|
226
|
+
# @option options [Boolean] :dynamo_db_big_decimals (true) When +true+,
|
227
|
+
# {DynamoDB} will convert number values returned by {DynamoDB::Client}
|
228
|
+
# from strings to BigDecimal objects. If you set this to +false+,
|
229
|
+
# they will be convereted from strings into floats (with a potential
|
230
|
+
# # backwards to test xml ordering loss of precision).
|
231
|
+
#
|
212
232
|
# @option options [String] :dynamo_db_endpoint ('dynamodb.amazonaws.com')
|
213
233
|
# The service endpoint for Amazon DynamoDB.
|
214
234
|
#
|
data/lib/aws/core/client.rb
CHANGED
@@ -356,15 +356,6 @@ module AWS
|
|
356
356
|
end
|
357
357
|
|
358
358
|
def populate_error response
|
359
|
-
response.error = extract_error(response)
|
360
|
-
end
|
361
|
-
|
362
|
-
# If the response contains error, this method will construct
|
363
|
-
# and return an error object. If no error is contained in the
|
364
|
-
# response, then nil is returned.
|
365
|
-
# @param [Response] response
|
366
|
-
# @return [Errors::Base,nil]
|
367
|
-
def extract_error response
|
368
359
|
|
369
360
|
status = response.http_response.status
|
370
361
|
|
@@ -377,14 +368,25 @@ module AWS
|
|
377
368
|
error_message
|
378
369
|
]
|
379
370
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
371
|
+
response.error =
|
372
|
+
case
|
373
|
+
when response.network_error? then NetworkError.new
|
374
|
+
when error_code then error_class(error_code).new(*error_args)
|
375
|
+
when status >= 500 then Errors::ServerError.new(*error_args)
|
376
|
+
when status >= 300 then Errors::ClientError.new(*error_args)
|
377
|
+
else nil # no error
|
378
|
+
end
|
379
|
+
|
380
|
+
end
|
387
381
|
|
382
|
+
# Extracts the error code and error message from a response
|
383
|
+
# if it contains an error. Returns nil otherwise. Should be defined
|
384
|
+
# in sub-classes (e.g. QueryClient, RESTClient, etc).
|
385
|
+
# @param [Response] response
|
386
|
+
# @return [Array<Code,Message>,nil] Should return an array with an
|
387
|
+
# error code and message, or +nil+.
|
388
|
+
def extract_error_details response
|
389
|
+
raise NotImplementedError
|
388
390
|
end
|
389
391
|
|
390
392
|
# Given an error code string, this method will return an error class.
|
@@ -511,44 +513,111 @@ module AWS
|
|
511
513
|
user_agent
|
512
514
|
end
|
513
515
|
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
def self.add_client_request_method method_name, options = {}, &block
|
516
|
+
class << self
|
517
|
+
|
518
|
+
# @return [Array<Symbol>] Returns a list of service operations as
|
519
|
+
# method names supported by this client.
|
520
|
+
def operations
|
521
|
+
@operations ||= []
|
522
|
+
end
|
522
523
|
|
523
|
-
|
524
|
+
# @private
|
525
|
+
def request_builders
|
526
|
+
@request_builders ||= {}
|
527
|
+
end
|
528
|
+
|
529
|
+
# @private
|
530
|
+
def response_parsers
|
531
|
+
@response_parsers ||= {}
|
532
|
+
end
|
533
|
+
|
534
|
+
protected
|
535
|
+
|
536
|
+
# Define this in sub-classes (e.g. QueryClient, RESTClient, etc)
|
537
|
+
def request_builder_for api_config, operation
|
538
|
+
raise NotImplementedError
|
539
|
+
end
|
524
540
|
|
525
|
-
|
541
|
+
# Define this in sub-classes (e.g. QueryClient, RESTClient, etc)
|
542
|
+
def response_parser_for api_config, operation
|
543
|
+
raise NotImplementedError
|
544
|
+
end
|
545
|
+
|
546
|
+
# Adds a single method to the current client class. This method
|
547
|
+
# yields a request method builder that allows you to specify how:
|
548
|
+
#
|
549
|
+
# * the request is built
|
550
|
+
# * the response is processed
|
551
|
+
# * the response is stubbed for testing
|
552
|
+
#
|
553
|
+
def add_client_request_method method_name, options = {}, &block
|
554
|
+
|
555
|
+
operations << method_name
|
556
|
+
|
557
|
+
ClientRequestMethodBuilder.new(self, method_name, &block)
|
558
|
+
|
559
|
+
method_def = <<-METHOD
|
560
|
+
def #{method_name}(*args, &block)
|
561
|
+
options = args.first ? args.first : {}
|
562
|
+
client_request(#{method_name.inspect}, options, &block)
|
563
|
+
end
|
564
|
+
METHOD
|
565
|
+
|
566
|
+
module_eval(method_def)
|
567
|
+
|
568
|
+
end
|
569
|
+
|
570
|
+
# Loads the API configuration for the given API version.
|
571
|
+
# @param [String] api_version The API version date string
|
572
|
+
# (e.g. '2012-01-05').
|
573
|
+
# @return [Hash]
|
574
|
+
def load_api_config api_version
|
575
|
+
lib = File.dirname(File.dirname(__FILE__))
|
576
|
+
path = "#{lib}/api_config/#{service_name}-#{api_version}.yml"
|
577
|
+
YAML.load(File.read(path))
|
578
|
+
end
|
579
|
+
|
580
|
+
# Defines one method for each service operation described in
|
581
|
+
# the API configuration.
|
582
|
+
# @param [String] api_version
|
583
|
+
def define_client_methods api_version
|
584
|
+
|
585
|
+
const_set(:API_VERSION, api_version)
|
586
|
+
|
587
|
+
api_config = load_api_config(api_version)
|
588
|
+
|
589
|
+
api_config[:operations].each do |operation|
|
590
|
+
|
591
|
+
builder = request_builder_for(api_config, operation)
|
592
|
+
parser = response_parser_for(api_config, operation)
|
593
|
+
|
594
|
+
define_client_method(operation[:method], builder, parser)
|
526
595
|
|
527
|
-
method_def = <<-METHOD
|
528
|
-
def #{method_name}(*args, &block)
|
529
|
-
options = args.first ? args.first : {}
|
530
|
-
client_request(#{method_name.inspect}, options, &block)
|
531
596
|
end
|
532
|
-
|
597
|
+
end
|
533
598
|
|
534
|
-
|
599
|
+
def define_client_method method_name, builder, parser
|
535
600
|
|
536
|
-
|
601
|
+
request_builders[method_name] = builder
|
602
|
+
response_parsers[method_name] = parser
|
537
603
|
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
604
|
+
add_client_request_method(method_name) do
|
605
|
+
|
606
|
+
configure_request do |request, request_options|
|
607
|
+
builder.populate_request(request, request_options)
|
608
|
+
end
|
609
|
+
|
610
|
+
process_response do |response|
|
611
|
+
response.data = parser.extract_data(response)
|
612
|
+
end
|
613
|
+
|
614
|
+
simulate_response do |response|
|
615
|
+
response.data = parser.simulate
|
616
|
+
end
|
617
|
+
|
618
|
+
end
|
619
|
+
end
|
547
620
|
|
548
|
-
# @return [Array<Symbol>] Returns a list of service operations as
|
549
|
-
# method names supported by this client.
|
550
|
-
def self.operations
|
551
|
-
@operations ||= []
|
552
621
|
end
|
553
622
|
|
554
623
|
# @private
|
@@ -69,6 +69,12 @@ module AWS
|
|
69
69
|
# @attr_reader [String] cloud_formation_endpoint ('cloudformation.us-east-1.amazonaws.com')
|
70
70
|
# The service endpoint for AWS CloudFormation.
|
71
71
|
#
|
72
|
+
# @attr_reader [Boolean] dynamo_db_big_decimals (true) When +true+,
|
73
|
+
# {DynamoDB} will convert number values returned by {DynamoDB::Client}
|
74
|
+
# from strings to BigDecimal objects. If you set this to +false+,
|
75
|
+
# they will be convereted from strings into floats (with a potential
|
76
|
+
# loss of precision).
|
77
|
+
#
|
72
78
|
# @attr_reader [String] dynamo_db_endpoint ('dynamodb.us-east-1.amazonaws.com')
|
73
79
|
# The service endpoint for Amazon DynamoDB.
|
74
80
|
#
|
@@ -16,7 +16,7 @@ require 'thread'
|
|
16
16
|
module AWS
|
17
17
|
module Core
|
18
18
|
module Http
|
19
|
-
|
19
|
+
|
20
20
|
# @private
|
21
21
|
class CurbHandler
|
22
22
|
|
@@ -86,10 +86,10 @@ module AWS
|
|
86
86
|
|
87
87
|
private
|
88
88
|
def make_easy_handle request, response, thread = nil
|
89
|
-
|
89
|
+
|
90
90
|
protocol = request.use_ssl? ? 'https' : 'http'
|
91
91
|
url = "#{protocol}://#{request.host}:#{request.port}#{request.uri}"
|
92
|
-
|
92
|
+
|
93
93
|
curl = Curl::Easy.new(url)
|
94
94
|
# curl.verbose = true
|
95
95
|
request.headers.each {|k, v| curl.headers[k] = v}
|
@@ -16,7 +16,7 @@ require 'httparty'
|
|
16
16
|
module AWS
|
17
17
|
module Core
|
18
18
|
module Http
|
19
|
-
|
19
|
+
|
20
20
|
# Makes HTTP requests using HTTParty. This is the default
|
21
21
|
# handler, so you don't need to do anything special to configure
|
22
22
|
# it. However, you can directly instantiate this class in order
|
@@ -31,11 +31,11 @@ module AWS
|
|
31
31
|
# )
|
32
32
|
#
|
33
33
|
class HTTPartyHandler
|
34
|
-
|
34
|
+
|
35
35
|
# @return [Hash] The default options to send to HTTParty on each
|
36
36
|
# request.
|
37
37
|
attr_reader :default_request_options
|
38
|
-
|
38
|
+
|
39
39
|
# Constructs a new HTTP handler using HTTParty.
|
40
40
|
#
|
41
41
|
# @param [Hash] options Default options to send to HTTParty on
|
@@ -48,25 +48,25 @@ module AWS
|
|
48
48
|
def initialize options = {}
|
49
49
|
@default_request_options = options
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
include HTTParty
|
53
|
-
|
53
|
+
|
54
54
|
class NoOpParser < HTTParty::Parser
|
55
55
|
SupportedFormats = {}
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def handle(request, response)
|
59
|
-
|
59
|
+
|
60
60
|
opts = default_request_options.merge({
|
61
61
|
:body => request.body,
|
62
62
|
:parser => NoOpParser
|
63
63
|
})
|
64
|
-
|
64
|
+
|
65
65
|
if request.proxy_uri
|
66
66
|
opts[:http_proxyaddr] = request.proxy_uri.host
|
67
67
|
opts[:http_proxyport] = request.proxy_uri.port
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
if request.use_ssl?
|
71
71
|
protocol = 'https'
|
72
72
|
opts[:ssl_ca_file] = request.ssl_ca_file if request.ssl_verify_peer?
|
@@ -75,21 +75,21 @@ module AWS
|
|
75
75
|
end
|
76
76
|
|
77
77
|
url = "#{protocol}://#{request.host}:#{request.port}#{request.uri}"
|
78
|
-
|
78
|
+
|
79
79
|
# get, post, put, delete, head
|
80
80
|
method = request.http_method.downcase
|
81
|
-
|
81
|
+
|
82
82
|
# Net::HTTP adds this header for us when the body is
|
83
83
|
# provided, but it messes up signing
|
84
84
|
headers = { 'content-type' => '' }
|
85
|
-
|
85
|
+
|
86
86
|
# headers must have string values (net http calls .strip on them)
|
87
87
|
request.headers.each_pair do |key,value|
|
88
88
|
headers[key] = value.to_s
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
opts[:headers] = headers
|
92
|
-
|
92
|
+
|
93
93
|
begin
|
94
94
|
http_response = self.class.send(method, url, opts)
|
95
95
|
unless http_response.nil?
|
@@ -105,7 +105,7 @@ module AWS
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
# We move this from AWS::Http to AWS::Core::Http, but we want the
|
108
|
+
# We move this from AWS::Http to AWS::Core::Http, but we want the
|
109
109
|
# previous default handler to remain accessible from its old namesapce
|
110
110
|
# @private
|
111
111
|
module Http
|
data/lib/aws/core/json_client.rb
CHANGED
@@ -11,94 +11,36 @@
|
|
11
11
|
# ANY KIND, either express or implied. See the License for the specific
|
12
12
|
# language governing permissions and limitations under the License.
|
13
13
|
|
14
|
-
require 'json'
|
15
|
-
|
16
14
|
module AWS
|
17
15
|
module Core
|
18
|
-
|
19
|
-
# = AWS::Core::Client::JSON
|
20
|
-
#
|
21
|
-
# Clients extend this module if the service they represent are
|
22
|
-
# AWS Query services that accept and return JSON.
|
23
|
-
#
|
24
|
-
module JSONClient
|
25
|
-
|
26
|
-
# Constructs the option grammars, one per service operation.
|
27
|
-
# @private
|
28
|
-
def self.extended base
|
29
|
-
base.send(:include, ErrorParser)
|
30
|
-
base.send(:define_grammars)
|
31
|
-
end
|
32
|
-
|
33
|
-
# @return [Hash<Symbol,OptionGrammar>] Returns a hash option
|
34
|
-
# grammars. Keys are method names (operations) and values are
|
35
|
-
# request option grammars that convert a ruby hash of options
|
36
|
-
# into a JSON document.
|
37
|
-
# @private
|
38
|
-
def option_grammars
|
39
|
-
@option_grammars ||= {}
|
40
|
-
end
|
16
|
+
class JSONClient < Core::Client
|
41
17
|
|
42
18
|
protected
|
43
19
|
|
44
|
-
|
45
|
-
|
46
|
-
# and defines one request method per operation.
|
47
|
-
def define_grammars
|
48
|
-
api_config[:operations].each do |op|
|
49
|
-
option_grammars[op[:method]] = OptionGrammar.customize(op[:inputs])
|
50
|
-
end
|
20
|
+
def self.request_builder_for api_config, operation
|
21
|
+
JSONRequestBuilder.new(api_config[:target_prefix], operation)
|
51
22
|
end
|
52
23
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
configure_request do |request, options|
|
57
|
-
|
58
|
-
parser = self.class.option_grammars[method_name]
|
59
|
-
x_amz_target = self.class::TARGET_PREFIX + operation
|
60
|
-
|
61
|
-
request.headers["content-type"] = "application/x-amz-json-1.0"
|
62
|
-
request.headers["x-amz-target"] = x_amz_target
|
63
|
-
request.body = parser.to_json(options)
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
process_response do |response|
|
68
|
-
response_body = response.http_response.body
|
69
|
-
response_body = "{}" if response_body == ""
|
70
|
-
data = ::JSON.load(response_body)
|
71
|
-
MetaUtils.extend_method(response, :data) { data }
|
72
|
-
end
|
73
|
-
|
74
|
-
simulate_response do |response|
|
75
|
-
data = {}
|
76
|
-
MetaUtils.extend_method(response, :data) { data }
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
24
|
+
def self.response_parser_for api_config, operation
|
25
|
+
JSONResponseParser.new(operation[:outputs])
|
80
26
|
end
|
81
27
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
else
|
96
|
-
message = json['message']
|
97
|
-
end
|
98
|
-
[code, message]
|
28
|
+
def extract_error_details response
|
29
|
+
if
|
30
|
+
response.http_response.status >= 300 and
|
31
|
+
body = response.http_response.body and
|
32
|
+
json = (::JSON.load(body) rescue nil) and
|
33
|
+
type = json["__type"] and
|
34
|
+
matches = type.match(/\#(.*)$/)
|
35
|
+
then
|
36
|
+
code = matches[1]
|
37
|
+
if code == 'RequestEntityTooLarge'
|
38
|
+
message = 'Request body must be less than 1 MB'
|
39
|
+
else
|
40
|
+
message = json['message']
|
99
41
|
end
|
42
|
+
[code, message]
|
100
43
|
end
|
101
|
-
|
102
44
|
end
|
103
45
|
|
104
46
|
end
|