Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faraday standard error being trapped #153

Open
kbaum opened this issue Dec 20, 2019 · 0 comments · May be fixed by #154
Open

Faraday standard error being trapped #153

kbaum opened this issue Dec 20, 2019 · 0 comments · May be fixed by #154

Comments

@kbaum
Copy link

kbaum commented Dec 20, 2019

Ran into this error:

NoMethodError: undefined method `body' for #<Hash:0x00007f83c0310fd8>
  from solidus_avatax_certified/response/base.rb:13:in `result'
  from tax_svc.rb:49:in `handle_response'
  from tax_svc.rb:43:in `validate_address'
  from solidus_avatax_certified/address.rb:53:in `validation_response'
  from solidus_avatax_certified/address.rb:46:in `validate'
  from models/solidus_avatax_certified/spree/order_decorator.rb:47:in `validate_ship_address'

I have not been able to reproduce it again as it seems related to an error being raised from avatax api that is no longer happening. From what I can see, validate_address is trapping the exception and changing the request to point at a Hash.

  def validate_address(address)
    begin
      request = client.addresses.validate(address)
    rescue StandardError => e
      logger.error(e)

      request = { 'error' => { 'message' => e } }
    end

    response = SolidusAvataxCertified::Response::AddressValidation.new(request)
    handle_response(response)
  end

Then handle_response calls response.result

  def handle_response(response)
    result = response.result
    begin
      if response.error?
        raise SolidusAvataxCertified::RequestError, result
      end

      logger.debug(result, response.description + ' Response')
    rescue SolidusAvataxCertified::RequestError => e
      logger.error(e.message, response.description + ' Error')
      raise if raise_exceptions?
    end

    response
  end

This calls faraday.body but now faraday is pointing at a Hash and we get this error:

 def result
   @result ||= faraday.body
 end

Let me know if this makes sense. Thx.

@kbaum kbaum changed the title Faraday standard error being swallowed Faraday standard error being trapped. Dec 20, 2019
@kbaum kbaum changed the title Faraday standard error being trapped. Faraday standard error being trapped Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant