CustomerInfoResponseHandler: return CustomerInfo instead of error if the response was successful#1778
Conversation
6294bb3 to
dfb5bb4
Compare
8bf0e45 to
5582a89
Compare
dfb5bb4 to
88d2c06
Compare
… if the response was successful Fixes [SDKONCALL-62]. The behavior in version 3.x was that we would return a `CustomerInfo` AND the attribute errors. [The test in that version](https://github.com/RevenueCat/purchases-ios/blob/3.14.2/PurchasesTests/SubscriberAttributes/BackendSubscriberAttributesTests.swift#L370-L404) however only verified that the error was returned. When we converted `(Value, Error)` callbacks to using `Result` (#1387), I assumed this was an error. Because of that incomplete test, we didn't notice this wasn't the desired behavior. If the backend returns a 200, it's assumed that the errors aren't more important than the correct `CustomerInfo`. The new implementation simply logs the attribute errors (which is now tested), and returns the `CustomerInfo`.
88d2c06 to
112d636
Compare
|
|
||
| var loggedMessages = [String]() | ||
| let originalLogHandler = Logger.logHandler | ||
| defer { Logger.logHandler = originalLogHandler } |
There was a problem hiding this comment.
😮 Didn't know about this. Interesting!
| return ErrorUtils.backendError( | ||
| withBackendCode: self.code, | ||
| backendMessage: self.message, | ||
| message: self.attributeErrors.description, |
There was a problem hiding this comment.
Hmm are we still using the backendMessage parameter anywhere? I couldn't find a usage of it but I might be wrong.
There was a problem hiding this comment.
Oh good catch! I changed this before I fixed #1776 and forgot to add it back. Thanks for the thorough review 👏🏻
| @@ -0,0 +1,29 @@ | |||
| { | |||
| "headers" : { | |||
There was a problem hiding this comment.
Just to make sure, these files are snapshots of the requests done during the unit tests. Then the tests check that the request remains the same, correct? This is nice!
There was a problem hiding this comment.
Yup exactly :) without needing to check each thing individually.
taquitos
left a comment
There was a problem hiding this comment.
Ugh, this review was sitting in draft.
There was a problem hiding this comment.
I think we should make a new API so this error logging is explicit
There was a problem hiding this comment.
I agree. I didn't feel too bad about this instance because it's covered by a test, so removing it would make it fail.
I don't love the implicit logging, but I think explicit logging of errors everywhere would be even worse :/ so I'm not sure how to improve this at the moment.
There was a problem hiding this comment.
Yeah, that's a great point, as long as it's covered by a test, this is much more palatable 😄
### Fixes: * `CustomerInfoResponseHandler`: return `CustomerInfo` instead of error if the response was successful (#1778) via NachoSoto (@NachoSoto) * Error logging: `logErrorIfNeeded` no longer prints message if it's the same as the error description (#1776) via NachoSoto (@NachoSoto) * fix another broken link in docC docs (#1777) via aboedo (@aboedo) * fix links to restorePurchase (#1775) via aboedo (@aboedo) * fix getProducts docs broken link (#1772) via aboedo (@aboedo) ### Improvements: * `Logger`: wrap `message` in `@autoclosure` to avoid creating when `LogLevel` is disabled (#1781) via NachoSoto (@NachoSoto) ### Other changes: * Lint: fixed `SubscriberAttributesManager` (#1774) via NachoSoto (@NachoSoto)
Follow up to #1776. That PR added a lot of tests to cover error logging, and #1778 introduced a small error that wasn't covered: if attribute errors are empty, the `localizedDescription` could end up becoming `"[:]"`. This fixes that. ## Examples: This was the underlying error returned (the output of `error.localizedDescription`): #### Before: > [:] #### After: > There was a credentials issue. Check the underlying error for more details. And this is what was logged (notice that I also fixed `ErrorCode.invalidCredentialsError` to not log as an "Apple Error"): #### Before: > 🍎‼️ There was a credentials issue. Check the underlying error for more details. [:] #### After: > 😿‼️ There was a credentials issue. Check the underlying error for more details.
Follow up to #1776. That PR added a lot of tests to cover error logging, and #1778 introduced a small error that wasn't covered: if attribute errors are empty, the `localizedDescription` could end up becoming `"[:]"`. This fixes that. ## Examples: This was the underlying error returned (the output of `error.localizedDescription`): #### Before: > [:] #### After: > There was a credentials issue. Check the underlying error for more details. And this is what was logged (notice that I also fixed `ErrorCode.invalidCredentialsError` to not log as an "Apple Error"): #### Before: > 🍎‼️ There was a credentials issue. Check the underlying error for more details. [:] #### After: > 😿‼️ There was a credentials issue. Check the underlying error for more details.
Fixes SDKONCALL-62.
The behavior in version 3.x was that we would return a
CustomerInfoAND the attribute errors. The test in that version however only verified that the error was returned.When we converted
(Value, Error)callbacks to usingResult(#1387), I assumed this was an error. Because of that incomplete test, we didn't notice this wasn't the desired behavior.If the backend returns a 200, it's assumed that the errors aren't more important than the correct
CustomerInfo.The new implementation simply logs the attribute errors (which is now tested), and returns the
CustomerInfo: