2

Yesterday, I went to http://try.discourse.org, the new project developed by the Stack Overflow team. This project uses the EmberJs javascript Framework for requesting the content. And unfortunately my browser (Safari) sees the following error in the code:

TypeError: 'undefined' is not an object (evaluating 'PreloadStore.get("siteSettings").top_menu')

The consequence of this error is that no content is displayed; I have a blank page. The javascript error logically prevents the content from displaying.

My question is:

If javascript is disabled in my browser, I can see the content of Dicourse because of the <noscript> </noscript> tag in html.

But if I have javascript enabled and it encounters an error, I can see nothing.

So, in a web app development, is there a way to display the no script content or alternative content if the javascript app encounters an error?

Undo
  • 25,519
  • 37
  • 106
  • 129
jeremieca
  • 1,156
  • 2
  • 13
  • 38
  • You can try using try/catch blocks to catch errors and avoid the js to break – Pablo Mescher Jun 03 '13 at 17:38
  • Try catch works well in asynchronous language ? Do you think a simple try catch around all the js application is enough ? – jeremieca Jun 03 '13 at 17:39
  • 1
    first thing: set a timeout that shows the fallback content after a while. then clear the timeout in the final block of code that's supposed to run, so the is fallback never shown if the code runs to the end. – dandavis Jun 03 '13 at 17:49
  • Well, try catch won't catch an error on an asynchronous callback.. however I doubt that is the cause of your content not displaying. An asynchronous call should give enough time for the html to be at least partially parsed before stopping – Pablo Mescher Jun 03 '13 at 18:03
  • 1
    Maybe do some global error handling? http://stackoverflow.com/questions/951791/javascript-global-error-handling – landons Jun 03 '13 at 18:49
  • Thanks. It's a good solution. Don't hesitate to propose new way. :) – jeremieca Jun 03 '13 at 19:33

1 Answers1

1

You can handle all errors that take place in AngularJS world by overwriting the $exceptionHandler service in your application : http://docs.angularjs.org/api/ng.$exceptionHandler

AngularJS prevents exceptions taking place in angular world to crash the browser :)

basarat
  • 261,912
  • 58
  • 460
  • 511