Not able to find 'x-amzn-requestid' when ConditionalCheckFailedException happen
We are using the Dynamoid Gem in our project
We are currectly want to implement Exception handling from the Dynamoid
Different types of exceptions are handled by
begin
// some code where exception may happen
rescue Exception => e
p e.message
end
For ConditionalCheckFailedException we are not able to get e.http_response.headers["x-amzn-requestid"]
Hi, @manabendrawelcome.
- The exception class you're catching is
Dynamoid::Errors::ConditionalCheckFailedExceptionrather than assumed/expectedAws::DynamoDB::Errors::ConditionalCheckFailedException. Dynamoid's exception wraps the original exception, which you can reach using the#inner_exceptionmethod. This wrapper exists for compatibility with ActiveRecord. - Even on
Aws::DynamoDB::Errors::ConditionalCheckFailedException, you cannot reach forhttp_responsedirectly -- that method does not exist as per the SDK. Instead you have to go through#context. Here's an example. - Unrelated, but a bonus: avoid rescuing Exception.
I am glad you're using Dynamoid! Please continue reporting any potential issues and suggestions.
Hi phillipmw... Thanks for your reply. We are using sdk 1 and when exception occurring dynamoid block catching the exception And I am still not getting any #context or 'x-amzn-requestid' below is the code...
begin d = Dynamo::DeviceStreamName.new d.id = "111" d.save rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException => e p "error happen" rescue Dynamoid::Errors::ConditionalCheckFailedException => e p "error happen111" e.methods end
Response:
"error happen111" => [:exception, :==, :to_s, :message, :inspect, :backtrace, :set_backtrace, :blame_file!, :blamed_files, :describe_blame, :copy_blame!, :in?, :psych_to_yaml, :to_yaml_properties, :to_yaml, :blank?, :present?, :presence, :acts_like?, :try, :html_safe?, :duplicable?, :to_json, :instance_values, :instance_variable_names, :as_json, :attr_encrypted_options=, :`, :to_param, :to_query, :with_options, :methods, :private_methods, :protected_methods, :public_methods, :singleton_methods, :dclone, :pry, :binding, :is_haml?, :map_csv, :import, :map_csv_with_data, :send_mail, :send_mail_with_subject, :send_welcome_mail, :send_device_share_invitation, :send_batch_location_convert_report, :send_recurly_exception_mail, :send_s3_folder_cleanup_report, :send_hubble_device_issue_mail, :send_free_trial_mail, :send_free_trial_expiring_mail, :send_free_trial_expired_mail, :send_generic_mail, :pretty_print, :pretty_print_cycle, :pretty_print_instance_variables, :pretty_print_inspect, :to_v8, :to_ruby, :delay, :delay, :send_later, :send_at, :require_all, :require_rel, :load_all, :load_rel, :autoload_all, :autoload_rel, :decrypt, :encrypt, :evaluated_attr_encrypted_options_for, :evaluate_attr_encrypted_option, :require_or_load, :require_dependency, :require_association, :load_dependency, :load, :require, :unloadable, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :gem, :psych_y, :class_eval, :silence_warnings, :enable_warnings, :with_warnings, :silence_stderr, :silence_stream, :suppress, :capture, :silence, :quietly, :debugger, :breakpoint, :ai, :awesome_inspect, :awesome_print, :suppress_warnings, :require_with_backports, :pretty_inspect, :equal?, :!, :!=, :instance_eval, :instance_exec, :send, :id]
Ah, my comment about #inner_exception is true only for the most recent version of Dynamoid, version 1.0.0. Naturally, I suggest you use the most recent version of all your gems.
With the older version, there isn't a way to get the instance of AWS::DynamoDB::Errors::ConditionalCheckFailedException -- in the code you're using, https://github.com/Dynamoid/Dynamoid/blob/v0.7.1/lib/dynamoid/adapter/aws_sdk.rb, Dynamoid::Errors::ConditionalCheckFailedException isn't a wrapper at all. We just catch the original exception from AWS SDK and re-throw a different exception.
So, if you need that header, upgrade to gem version 1. :)