1

As with any application a number of things can go wrong sooner or later. I have a large Vue application that sometimes throws some errors (I know, it shouldn't, but sometimes it does anyway) and I'd like to show a friendly message to the user so they won't be stuck waiting. Like a "generic error handler" of some kind on the window object.

I tried this: javascript: how to display script errors in a popup alert? but it does not fire.

Any other suggestions?

Nick M
  • 2,424
  • 5
  • 34
  • 57

1 Answers1

2

You could redirect to a generic error page which displays an error ID and the message (if given).

A different way would be to display toasts and stay on the page, which will allow the user to retry actions. I recommend vue-toasted for toasts in vue projects.

sandrooco
  • 8,016
  • 9
  • 48
  • 86
  • 2
    I could do a lot of things if the window.onerror event would fire. Including sending myself a text message, sending a wake-on-lan packet to my dev box, and turning on the espresso machine so I can get to work to fix whatever went wrong. But since the window.onerror event does not fire I get calls from users sometimes saying the page froze ("I've been waiting for it for the past 3 hours"). Thanks for the toasted tip, putting it on my to-do list. – Nick M Sep 14 '17 at 16:49
  • You could just throw the errors when something breaks and then catch them in a error handler as described in my answer? – sandrooco Sep 14 '17 at 16:51
  • As a last resort, yeah, but I'd prefer not to. – Nick M Sep 14 '17 at 19:35
  • Throwing (and catching!) is a best practice. There's always something that could happen. – sandrooco Sep 15 '17 at 06:32