-
Notifications
You must be signed in to change notification settings - Fork 12
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
[rfc] use spree default calculator when taxjar is down #60
Comments
Instead of returning |
I'm certainly open to making that an option and it would be very easy to implement: just call the default calculator and return that. |
Hey @AdnanTheExcellent thanks for the RFC! How do you feel about something like this? # config/initializers/taxjar.rb
SuperGood::SolidusTaxjar.exception_handler = ->(e) {
Rails.logger.error "An error occurred while fetching TaxJar tax rates - #{e}: #{e.message}"
# If TaxJar is down, we swap in the default tax calculator.
if e.is_a?(HTTP::ConnectionError)
Spree::Config.tax_calculator_class = Spree::TaxCalculator::Default
# This job is responsible for checking if TaxJar comes back up and then
# setting `Spree::Config.tax_calculator_class` to
# `SuperGood::SolidusTaxjar::TaxCalculator`.
TaxjarPingJob.perform_later
end
} We feel it may be undesirable to silently call the default tax calculator as there are lots of ways you could handle TaxJar being down (some stores may have other calculators to fallback on, special logging, etc). Suppose we did add some behavior around fallback calculators it could look like this: # config/initializers/taxjar.rb
SuperGood::SolidusTaxjar.fallback_calculator = SomeCustomCalculator |
So i don't think this will work. timeouts are not a StandardError, so Taxjar timing out wont be caught by the exception handler as it is now. I had to add rescue StandardError, Rack::Timeout::RequestTimeoutException => e
exception_handler.call(e)
::SuperGood::SolidusTaxJar.fallback_tax_calculator.new(order).calculate
end the fallback calculator could literally be
this is exactly what i'm trying to do. my fallback calculators look something like: self.fallback_tax_calculator = ::Spree::TaxCalculator::Default
self.fallback_tax_rate_calculator = -> (address) { ::Spree::TaxRate.for_address(address)&.first&.amount } |
On a slightly related note, i have a custom |
@AdnanTheExcellent we think the request for a fallback calculator is reasonable and valuable. We have added two tickets to capture that work #61 #62 . Let's continue the discussion on those tickets if you have more thoughts and close this RFC |
So..taxjar is currently down. Getting a lot of Rack::Timeout::RequestTimeoutException errors. What do you think would be the best way to handle that? rescuing StandardError does not catch that error.
The text was updated successfully, but these errors were encountered: