error-reporting
Easy-to-use error reporting
Installation
npm install --save trackthis-error-reporting
Usage
// Load the modulevar tter = ; // Initialize a reporter with default values in scope 'scope'var reporter = ; // Use the reporter to log 'Hello World'// Outputs (console.log) { code: '2ML7WOXUP2NAM.26PZVO9P3TYEP', level: 'INFO', description: 'Hello World' }// Returns 'Hello World'; // Report with a custom level// Outputs (console.log) { code: '2ML7WOXUP2NAM.26PZVO9P3TYEP', level: 'FATAL', description: 'Hello World' }// Returns 'Hello World'; // Initialize a reporter which saves the errors into an array of oursvar logArr = customReporter = reporter; // Outputs (console.log) { code: '2ML7WOXUP2NAM.26PZVO9P3TYEP', level: 'INFO', description: 'Hello World' }// Outputs (console.log) { code: '2ML7WOXUP2NAM.URTTQPNTWFPA' , level: 'INFO', description: 'foobar' }// Returns 'Hello World'// Returns 'foobar';; // Outputs [ { code: '2ML7WOXUP2NAM.26PZVO9P3TYEP', level: 'INFO', description: 'Hello World' },// { code: '2ML7WOXUP2NAM.URTTQPNTWFPA' , level: 'INFO', description: 'foobar' }// ]console;
Examples
Reporting an error for missing data
// Create the reporter for this file// I suggest using the filename as scope (__filename in nodejs)var tter = reporter = ; // An example function that fetches the user from it's cookie { // Log the errors into response.data.errors as well var reporter = reporter; // Fetch the user data from the cookie var cookieData = userData = cookieData && cookieDatajwt || false; // Return whether we were successful if userData ; else // Use the default reporting level ; // Or with custom reporting level ; }
Contributing
First, look at the issues page to ensure your issue isn't already known. If it's not, you can create a new issue with a detailed description of what happened & how to reproduce the unexpected behavior.
If you decide to take on the challenge of fixing a known (or unknown) issue, you can do so by sending in a pull request from your own fork of the project. Once it has been tested (manually for now) and approved, it will be merged into the master branch of the repository.