Custom VError
Simple class extending VError for easy custom error creation.
Usage
Here is the basic usage. For more use cases, see the tests.
1. Define your error
UserNotAllowedError.js
'use strict'; const CustomVError = ; // Replace UserNotAllowedError with your custom error namemoduleexports = { super...args; // Provide a default message thismessage = thismessage || 'User is not allowed to perform this action'; };
2. Throw your error
const UserNotAllowedError = ; { if !isAllowed throw // You can provide some error metadata. This will be appended to the message info: user_id: user_id }
3. Catch your error
try ; catch ex if ex instanceof UserNotAllowedError numberOfTimesUsersTriedToDoSomethingTheyWerentSupposedTo++; // This will log the default message and the metadata in following format: // "User is not allowed to perform this action user_id=FOO" console;