cookies
cookies copied to clipboard
clearAll should use promise resolution in all cases
The documentation indicates that clearAll
returns a promise that is always fulfilled with a boolean on whether the cookies were successfully cleared or not. (This is not explicitly stated, but that's what you gather from CookieManager.clearAll().then((success) => ...
with no catch clause.)
In reality, what is returned is:
iOS with useWebKit=false
- Always resolves true
iOS with useWebKit=true
- If on iOS 11.0 or greater: resolves true
- On older iOS version: rejects
- Resolves to a boolean indicating whether any cookies were cleared or not (but all possibly existing cookies are removed in any case)
Thus, the promise may be resolved of rejected, and in no case does the resolved boolean indicate whether it was successful or not – the only case in which it resolves to false is to indicate that there were no cookies present in the first place.
Nice catch, which behavior should be the accepted one?
Personally I was confused with the success
boolean, and in what case the operation could be unsuccessful and what to do then. (That's why I started digging into the code in the first place.) I also can't think of any use case for needing to know whether there were cookies that were cleared or not.
If designing it from scratch, I would probably return a promise that is fulfilled with no value, or rejected on iOS <11. This of course would be a breaking change.
Whatever the design, the most important thing is to have the cases clearly documented. The iOS version limitation is especially important. After noticing it I increased my iOS version requirement to 11 because in my use case it's unacceptable for the cookies not to be cleared.
@plaa thanks for the feedback, I agree with the promise resolution should be consistent in all cases. I'll make a note for this issue to address that