Sha256: a5f740272899ac4fc4c87341a03dd1fe2295327e5d7bfd78d8fba1961b8b4103

Contents?: true

Size: 655 Bytes

Versions: 5

Compression:

Stored size: 655 Bytes

Contents

# This module extends json_api_client's ParseJson service
# to make sure malformed repsonse bodies is always included as context in
# the thrown error message when json parsing fails.
module FlexCommerceApi
  module JsonApiClientExtension
    module ParseJson
      def call(environment)
        super
      rescue JSON::ParserError => error
        error.define_singleton_method(:raven_context) do
          {
            extra: {
              body: environment.body
            }  
          }
        end
        raise
      end
    end
  end
end

JsonApiClient::Middleware::ParseJson.send :prepend, FlexCommerceApi::JsonApiClientExtension::ParseJson

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flex_commerce_api-0.8.3 lib/flex_commerce_api/json_api_client_extension/parse_json.rb
flex_commerce_api-0.8.2 lib/flex_commerce_api/json_api_client_extension/parse_json.rb
flex_commerce_api-0.8.1 lib/flex_commerce_api/json_api_client_extension/parse_json.rb
flex_commerce_api-0.7 lib/flex_commerce_api/json_api_client_extension/parse_json.rb
flex_commerce_api-0.6.57 lib/flex_commerce_api/json_api_client_extension/parse_json.rb