-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Provider incorrectly marked as available + doesn't fallback to next provider in the chain #385
Comments
Well in my impression |
Yes, that's the case, ExchangeRateProvider has a default method isAvailable()
It is unrelated to any date or time. "defined" means as I hinted above that it is declared in the configuration. Will close this, as it works as designed. |
Ok, but in this case for The final exception message also doesn't make sense because |
Maybe @fprochazka remembers why he added that "fail early" exception instead of looping to another provider. Let's see, what @fprochazka might say and if he thinks there could be a different solution, but either way this would have to be an improvement for Moneta 1.5 or even a 2.x release. |
I wanted the entire operation (the business operation that is calling the exchange rates) to fail if one of the delegate providers threw an error because I've implemented a bunch of completely custom providers that sometimes could throw an exception if they failed for some critical reason (I've had e.g. database provider and if there were the table missing, it would rightfully throw a pretty critical exception) The problem is that the |
@fprochazka but in that case |
I don't think it beats the purpose, the problem is that the The problem starts with the fact, that the library as a whole doesn't have a very good definition of how to work with error states. |
…ney#385 This commit introduces a `failFast` parameter to the `getExchangeRate` method in the `CompoundRateProvider` class to work around the limitations described in issue JavaMoney#385. The `failFast` parameter helps mitigate the problem by allowing the caller to specify whether the method should return immediately on failure. Due to current API constraints, we cannot modify the `getExchangeRate` signature in the `ExchangeRateProvider` interface without causing breaking changes.
Modified the getExchangeRate method in the CompoundRateProvider class to introduce a failFast parameter. Previously, the method would immediately throw an exception on the first provider failure. This change allows for a more flexible approach by adding an option to continue attempting to get an exchange rate from subsequent providers if failFast is set to false. - Added a new overloaded getExchangeRate method with a failFast boolean parameter. - If failFast is true, the method retains the original behavior of failing immediately on the first exception. - If failFast is false, the method logs a warning and continues to the next provider in case of an exception. This update addresses some of the limitations described in issue JavaMoney#385.
Hello, I'm not sure if I've misunderstood how this works, but I'm trying to get exchange rate on a given date (which can be current or historic) and I'm following the suggestion from the docs of
ECBHistoricRateProvider
/ECBHistoric90RateProvider
:The default chain is defined like:
conversion.default-chain=IDENT,ECB,ECB-HIST90,ECB-HIST
I would assume that this means that
provider.getCurrencyConversion(conversionQuery)
would attempt each provider in the chain and move on if noCurrencyConversion
is available.However, looking a bit into the source code, I see that the
localDate
that gets set on the query isn't even inspected when searching for available providers. AlsoisAvailable
method (javax.money.convert.ExchangeRateProvider#isAvailable(javax.money.convert.ConversionQuery)
) doesn't really do what is expected, and as a result this error gets thrown:for this query:
Basically
ECB
is the first one to try conversion and fails instantly because, as expected, it doesn't have data for historic date2022-01-03
.My questions are:
ECB
provider flagged as available in the first place?ECB-HIST90
and attempt conversion there?Version:
1.4.2
The text was updated successfully, but these errors were encountered: