-
Notifications
You must be signed in to change notification settings - Fork 16
When to warn users when an error happens?
It's a good practice to give the user a feedback when something unexpected happens. In the GDPRConsentViewController
there are many moving parts and as with any piece of software that communicates with the external world, unexpected things happens all the time. In this wiki we describe an approach (developed together with @s-hintz) on deciding when you should warn users about an error and when not.
Long story short, you want to bother the user with an error message only if the consent UI was presented or when custom setting consent to a vendor (when using the customConsentTo
).
So the idea is to keep a flag, let's name it shouldWarnUserIfError
that will indicate if the user should be warned or not if an error happens (onError
is called).
This flag would be set to true
in 2 places:
- inside
onConsentUIWillShow
- every time you call
customConsentTo
And would be reset to false in 3 spots:
- inside onConsentReady
- inside onError
- inside the completion handler you pass to
customConsentTo
method
class MyViewController: UIViewController {
var shouldWarnUserIfError = false
var consentViewController: GDPRConsentViewController = { /* initialise SDK */ }
func enableVendor(withId vendorId: String) {
shouldWarnUserIfError = true
consentViewController.customConsentTo(vendors: [vendorId], categories: [], legIntCategories: []) {
// successful response from customConsentTo
shouldWarnUserIfError = false
}
}
}
extension MyViewController: GDPRConsentDelegate {
func gdprConsentUIWillShow() {
shouldWarnUserIfError = true
// rest of implementation
}
func onConsentReady(gdprUUID: GDPRUUID, userConsent: GDPRUserConsent) {
shouldWarnUserIfError = false
// rest of implementation
}
func onError(error: GDPRConsentViewControllerError?) {
if shouldWarnUserIfError {
// warn the user about what happened
}
// check if consent ui is presented and remove it
shouldWarnUserIfError = false
}
}