qerrors

1.1.2 • Public • Published

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 OMNICHAT_TOKEN in your environment, get your key at OmniChat.

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 });

Package Sidebar

Install

npm i qerrors

Weekly Downloads

28

Version

1.1.2

License

ISC

Unpacked Size

22.8 kB

Total Files

9

Last publish

Collaborators

  • bijikyu