Skip to content

Fix: Retry ViesCheck after rescuing from any Valvat Maintenance exception #3844

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

Merged
merged 9 commits into from
Jun 20, 2025

Conversation

diegocharles
Copy link
Contributor

@diegocharles diegocharles commented Jun 17, 2025

Fix VIES Maintenance exceptions handling

Problem

Valvat::MemberStateUnavailable exceptions weren't being raised properly, preventing fallback mechanisms from triggering when VIES is unavailable.

Some countries won't accept requests during the weekend of after the business hour.
Check the table here https://ec.europa.eu/taxation_customs/vies/#/help

Solution

  1. Added raise_error: true to Valvat calls in Customers::EuAutoTaxesService to ensure exceptions are properly raised and caught by the existing rescue block
  2. Update the wait time from 30 seconds to 15.minutes, in order to avoid overheads in the Sidekiq, since the job will run until it gets the information.

Next steps:

Rethink the retry logic to make it exponential using the Sidekiq built-in helper, or create a table with the working hours for each country.

Testing

  • ✅ All existing tests pass
  • ✅ VIES exceptions now properly trigger fallback mechanism
  • ✅ Webhook notifications work correctly
  • ✅ Retry job scheduling functions as expected

Impact

Better reliability for German customers when VIES service is temporarily unavailable, ensuring consistent tax application through proper fallback mechanisms.


Context:

# Before: Exception not raised
Valvat.new("DE199896394").exists?(detail: true)

# After: Exception properly raised and handled
Valvat.new("DE199896394").exists?(detail: true, raise_error: true)

What happens now:

  1. When VIES is unavailable, Valvat::MemberStateUnavailable is properly raised
  2. Existing rescue block captures the exception
  3. Webhook is sent with error details
  4. Retry job is scheduled for 30 seconds later

@diegocharles diegocharles marked this pull request as draft June 17, 2025 18:07
@diegocharles diegocharles marked this pull request as ready for review June 17, 2025 20:32
@diegocharles diegocharles marked this pull request as draft June 17, 2025 20:57
@diegocharles diegocharles marked this pull request as ready for review June 17, 2025 22:00
@diegocharles
Copy link
Contributor Author

@mariohd There are some overthinking from my end 💥

@brunomiguelpinto
Copy link
Contributor

We created an helper that might be useful on this ConcurrencyThrottlable, have a look to check if it's useful

@diegocharles diegocharles requested review from groyoh and mariohd June 18, 2025 12:58
@diegocharles diegocharles changed the title Fix: Retry ViesCheck within a exponential space of time Fix: Retry ViesCheck after rescuing from any Valvat Maintenance exception Jun 18, 2025
@diegocharles diegocharles merged commit 16ebdf9 into main Jun 20, 2025
14 checks passed
@diegocharles diegocharles deleted the fixes/retry_vies_check_job branch June 20, 2025 14:36
diegocharles added a commit that referenced this pull request Jul 11, 2025
…tion (#3844)

## Fix VIES Maintenance exceptions handling 

### Problem
`Valvat::MemberStateUnavailable` exceptions weren't being raised
properly, preventing fallback mechanisms from triggering when VIES is
unavailable.

Some countries won't accept requests during the weekend of after the
business hour.
Check the table here https://ec.europa.eu/taxation_customs/vies/#/help

### Solution

1. Added `raise_error: true` to Valvat calls in
`Customers::EuAutoTaxesService` to ensure exceptions are properly raised
and caught by the existing rescue block
2. Update the wait time from 30 seconds to 15.minutes, in order to avoid
overheads in the Sidekiq, since the job will run until it gets the
information.

### Next steps: 
Rethink the retry logic to make it exponential using the Sidekiq
built-in helper, or create a table with the working hours for each
country.

### Testing
- ✅ All existing tests pass
- ✅ VIES exceptions now properly trigger fallback mechanism
- ✅ Webhook notifications work correctly
- ✅ Retry job scheduling functions as expected

### Impact
Better reliability for German customers when VIES service is temporarily
unavailable, ensuring consistent tax application through proper fallback
mechanisms.

---

**Context:**
```ruby
# Before: Exception not raised
Valvat.new("DE199896394").exists?(detail: true)

# After: Exception properly raised and handled
Valvat.new("DE199896394").exists?(detail: true, raise_error: true)
```

**What happens now:**
1. When VIES is unavailable, `Valvat::MemberStateUnavailable` is
properly raised
3. Existing rescue block captures the exception
4. Webhook is sent with error details
5. Retry job is scheduled for 30 seconds later
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 this pull request may close these issues.

4 participants