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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jpd-express-error

v0.6.11

Published

A utility package for managing standardized error handling in Express microservices with strong typing.

Readme

jpd-express-error

jpd-express-error is a library for Express.js that provides standardized error handling for microservices.

It includes: • A middleware errorHandler to catch and format errors. • An JpdError class to throw custom errors with HTTP status codes. • A JpdResponse class to structure API responses. • Built-in handling for Prisma errors (P2002, P2025, etc.). • Dev/Prod distinction to return detailed messages in development and generic messages in production.


Installation

npm install jpd-express-error

Usage

Registering the errorHandler middleware

In your app.ts, add the errorHandler middleware after all routes:

import express from "express";
import { errorHandler } from "jpd-express-error";
import router from "./routes";

const app = express();
app.use(express.json());

// Define routes
app.use("/api", router);

// Error handling middleware
app.use(errorHandler);

// Start server
app.listen(3000, () => console.log("Server running"));

Throwing a custom error (JpdError)

You can throw a custom business error inside a controller, service or model :

import { JpdError, ERROR } from "jpd-express-error";

const getUser = async (req, res, next) => {
  const user = await prisma.user.findUnique({ where: { id: req.params.id } });

  if (!user) {
    throw new JpdError(ERROR.userNotFound, 404);
  }

  res.json({ success: true, data: user });
};

Structuring API responses with JpdResponse

Use JpdResponse to format your API responses :

import { JpdResponse, SUCCESS } from "jpd-express-error";

const createUser = async (req, res) => {
  const newUser = await prisma.user.create({ data: req.body });

  res.status(201).json(JpdResponse.success(SUCCESS.resourceCreatedSuccessfully, newUser));
};

Available Messages

✅ Success Messages

import { SUCCESS } from "jpd-express-error";

SUCCESS.resourceRetrievedSuccessfully
SUCCESS.resourceUpdatedSuccessfully
SUCCESS.resourceValidatedSuccessfully
SUCCESS.resourceCompletedSuccessfully
SUCCESS.operationSucceeded
SUCCESS.userLoggedInSuccessfully successfully
SUCCESS.userLoggedOutSuccessfully successfully
SUCCESS.userRegisteredSuccessfully
SUCCESS.profileUpdatedSuccessfully
SUCCESS.resourceCreatedSuccessfully
SUCCESS.resourceDeletedSuccessfully"

❌ Error Messages

import { ERROR } from "jpd-express-error";

// 400 Bad Request
ERROR.errorLoggingOut:
ERROR.invalidRequest:
ERROR.missingRequiredFields:
ERROR.invalidDataFormat:
ERROR.invalidRequestFormat:
ERROR.unsupportedMediaType:
ERROR.tooManyParameters:
ERROR.invalidQueryParameters:
ERROR.cartCreationFailed:
// 401 Unauthorized
ERROR.unauthorized:
ERROR.invalidPassword:
ERROR.invalidToken:
ERROR.tokenExpired:
ERROR.missingToken:
ERROR.invalidCredentials:
// 403 Forbidden
ERROR.forbidden:
ERROR.insufficientPermissions:
ERROR.accessDenied:
// 404 Not Found
ERROR.userNotFound:
ERROR.resourceNotFound:
ERROR.cartNotFound:
ERROR.productNotFound:
// 409 Conflict
ERROR.userAlreadyExists:
ERROR.emailAlreadyInUse:
ERROR.resourceAlreadyExists:
ERROR.foreignKeyConstraintFailed:
// 422 Unprocessable Entity
ERROR.validationError:
ERROR.invalidEmailFormat:
ERROR.passwordTooWeak:
// 429 Too Many Requests
ERROR.tooManyRequests:
ERROR.rateLimitExceeded:
// 500 Internal Server Error
ERROR.internalServerError:
ERROR.databaseConnectionError:
ERROR.fileUploadError:
ERROR.fileDeletionError:
ERROR.fileReadError:
ERROR.fileWriteError:

Customizing errors

You can add your own errors:

import { JpdError, ERROR } from "jpd-express-error";

// Adding a custom error
ERROR.customError = "Custom error message";

throw new JpdError(ERROR.customError, 400);

Contributing

Feel free to open issues or contribute by submitting pull requests! 🚀


License

This project is licensed under the ISC License.