publish event when page has page problems

I’m trying to see if I can adopt this code to unblock the UI if an error occurs, currently if the UI is blocked and an error occurs the screen stays blocked. Is there a way in the API to unblock the UI? What is the function call for that?

Thanks!