Error handling is really painful, and it’s easy to get by for a long time in node.js without dealing with errors correctly. However, building a node.js application that is scalable requires dealing with errors in the right way.
we can divide errors into two broad categories;
Operational errors: these represent run-time problems experience by correctly written programs. they are not really bugs but are problems attached to something else in our program. Examples of such errors can be a failure to connect to a database, failure to resolve hostname, request-timeout, invalid input from the user, and so on.
Programmer errors: these are bugs and should be dealt with in our code. they can always be avoided by changing some line(s) of code. Examples of such errors are; when a String is passed where an Object was expected, try to read a property that is “undefined”, called an asynchronous function without a callback, and so on.
we often use errors to mean both of these broad categories but they are quite different. Operational errors are usually error conditions that all programs must deal with. They don’t necessarily indicate a bug or a serious problem.
By contrast programmer errors are bugs. Sometimes we make mistakes in our code, maybe we forget to validate user input, mistyping a variable name, or even parse a String.
The distinction is very important; operational errors are part of the normal operation of a program while programmer error are bugs.