1.0.4 • Published 2 months ago
qerrors v1.0.4
qerrors
A middleware module to log errors and analyze them via an external AI API. Error logger that prints error stack and AI advice in the actual logs to resolve errors.
Environment Variables
You will need to set OPENAI_TOKEN in your environment.
License
ISC
Installation
npm install qerrors
Usage
// Import just qerrors:
const {qerrors} = require('qerrors');
// OR import both qErrors and logger:
const { qerrors, logger } = require('qerrors');
// Example of using qerrors as Express middleware:
app.use((err, req, res, next) => {
qerrors(err, 'RouteName', req, res, next);
});
// Using qerrors in any catch block:
function doFunction(req, res, next) {
try {
//code
} catch (error) {
qerrors(error, "doFunction", req, res, next); //req res and next are optional
}
}
// Example for javascript that is not express related (node / service code / biz logic)
function doFunction(param) {
try {
//code
} catch (error) {
qerrors(error, "doFunction", param);
}
}
// ... or if multiple params:
function doFunction(param1, param2) {
try {
//code
} catch (error) {
qerrors(error, "doFunction", {param1, param2});
}
}
// Using the Winston logger directly:
logger.info('Application started');
logger.warn('Something might be wrong');
logger.error('An error occurred', { errorDetails: error });