#Handle timeouts & errors

Access is, by design, dynamic. Which means that in order to show the right action at the right time for any particular user, it has to communicate with your dashboard. This comes with a lot of advantages, like great custom designs, texts & options, but with a tiny caveat: it can fail.

We, developers, know it better than anyone else: if we ever think something can fail, it will most certainly fail at a given time. And that's normal. Preparing for it is even a concept called Chaos Engineering.

At Poool, we decided to handle some part of it for you: if we can't communicate with your dashboard in less than 10sec or simply fail to do so, we will trigger a timeout, display a default (configurable) paywall, and fire an onError event providing a way for you to show your own fallback if the default one is not your cup of tea.
This is the best way to ensure your visitors have a consistant experience while visiting your site, and it can be achieved in various ways.

#Configure the default behavior

Historically, in case of an error from our end, we used to force the content to stay locked and to display a paywall asking for premium subscription. This is now a default behavior that can be customized.
Assuming you already know how to create a basic paywall, we can add a few lines of configuration to ensure the behavior matches what we want it to be:
Here, by setting the default_widget option to a widget called invisible we were able to unlock the content automatically when a network error occured. We can apply the same logic with the gift widget, for example, if we still want to unlock our premium content but want to ask our visitor to unlock it manually:
You can apply the same logic for any other other widget but we recommand you to use 'gift', 'unlock', 'invisible' or 'subscription' to prevent any troubleshoot coming from a network error.
Additionnaly, you can configure the time we use as a reference to abort any ongoing request and display a default paywall:
Pretty useful, but a bit limited if we can't have any of those fancy appearances we created on our dashboard anyway, isn't it?

#Add styles & texts inside the code

One of the most common message our support has received over the years is probably "why is my paywall suddenly black?". The answer is really simple: we couldn't get the custom appearance you created on your dashboard due to some network error, and that's your first visit so we never cached it.

To be able to get around this issue, we now strongly encourage to also set a bunch of custom styling & messages directly from within the integration code:
By doing so, you ensure that in case of any network (or similar) error, the default paywall that will be displayed has the same styling and tone as the rest of your site.

ℹ️ If everything goes fine network-wise and you didn't set any option as read-only, your dashboard configuration will override the one you set in the code. This paves the way for a great overall experience without any weird black paywall popping up below your flashy green page 😅

#Implement your own strategy

If you ever need to go further than that and want, for example, to display a Mailchimp newsletter form instead of a paywall in case of an error, you could also use the onError event and hide the default generated paywall to show whatever fits your needs.

Let's say we have a freshly-custom-built fancy newsletter form (simplified for the sake of the person writing this guide) below our premium content:
The form will be hidden in the page waiting for its time to shine, and all you need to do now is to handle the onError event:

Everything is now correctly set up 🚀 and we can move to our next guide where we'll see how we can take advantage of Access.js' companion library, Audit.js, to be able to use a unique feature called native segmentation.