npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@q5idservices/q5id-common

v1.0.13

Published

### Error Handler

Downloads

32

Readme

@q5idservices/q5id-common

Error Handler

Error Handler is taking care of handling all the errors. Below is the instruction on how to use the error handling.

Installation

npm install @q5idservices/q5id-common

Simple example

import { errorHandler, NotFoundError } from '@q5idservices/q5id-common';

// After all the routes and before the errorHandler
app.all('*', () => {
  throw new NotFoundError();
});

// Place Error handler right before you start the server
app.use(errorHandler);

// Server Start
app.listen(port);

List of all the Error Handlers

| Error Handlers | Function | Description | | ------------------------- | ------------------------- | --------------------- | | Bad Request Error | BadRequestError | Description coming... | | Custom Error | CustomError | Description coming... | | Database Connection Error | DatabaseConnectionError | Description coming... | | Not Found Error | NotFoundError | Description coming... |

Logger

The logger is logging everything separately to individual files or to the same file. It can be done both ways, log everything and separately. See example below.

Files will be created automatically. declaring

Logging Everything to ONE file

Import Logging and LoggingErrors to the index file. Its crucial to add Logging below you declare any routes and LoggingErrors right before you add a listener with the port. See example below.

List of all the Loggers

| Log Handlers | Import | Usage | Description | | -------------- | ----------------- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | | Logging All | {LoggingAll} | LoggingAll(app) | his in used to log all the routes with message and status. It has to be injected inside an index file, before all routes are declared. | | Logging Errors | {LoggingErrors} | LoggingErrors(app) | This in used to catch all errors (throw new Error). It has to be injected inside an index file, after all routes are declared. | | Custom Logging | {Log} | Log.Info("Message") Log.Warning("Message") Log.Error("Message") | This is made to log Error, Info, or Warning with custom message. |

  • Logging - Catching everything besides Errors and logging it to logsAll.log
  • LoggingErrors - Catching all the Errors. Specifically when it's throw new Error(...). These Errors cannot be caught by Logging function.
// import express -> import express, { Express } from 'express';

import { LoggingAll, LoggingErrors } from '@q5idservices/q5id-common';

// initialize express -> const app: Express = express();

// This need to be declared before all the routes
LoggingAll(app);

// ... declaring all the routes, modules, controller, middleware
// ALL ROUTES HERER

// This need to be declared after all the routes
LoggingErrors(app);

// Server Start
app.listen(port);

Log Custom

Import logger to the file you want to use custom logger

Logging Info

import { Log } = require('@q5idservices/q5id-common');

// Example of use
// level - specify the level of the log (example: "warning", "info", "error", etc). Mainly "info" if it goest to Info log
// message - specify the log message
app.get('/', (req: Request, res: Response) => {
  // Logging Custom info
  Log.Info('Info message')
  // Logging Custom Error
  Log.Error('Error message')
  // Logging Custom Warning
  Log.Warning('Warning message')
  res.send(...);
});

Changelog

Version 1.0.2

  • Finalizing logger. Adding Error Logger and Logging All

Version 1.0.0 (breaking)

  • Initial Publish of the package
    • ErrorHandling
    • Logger