Error handler with requirejs

Error handler with requireJs is very easy. As we all know the importance of error handling in application this topic helps you to understand the error handler concept in requireJs.

Error handler Method definition

By default in requireJs there are two methods which handles error.

  1. requireType
  2. requireModules

requireType:  This is a string value with a general classification, like “timeout”, “nodefine”, “scripterror”. timeout generally mean the delayed response time for the script from the server. scripterror generally mean 404 errors.

requireModules : This is used under the requireType to identify on which module error has occurred.

Steps to configure error handler

  1. In your application main.js or init.js you have to write code to configure the error handler with requireJs.
  2. onError handler method will catch all type of error with requireJs and handles in its way.

If you include above code in your application main.js or init.js on each error it will render onError method so that you can intimate the user about the error occurred in your application and on demand user can be requested to reload the application to fix the error.

Hope this helps!

Leave a Comment

Your email address will not be published. Required fields are marked *