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

@ahextechnology/sucess-error-responses

v1.1.1

Published

This module provides a set of classes and functions for handling errors and sending responses in a Node.js application. It includes custom error classes, a status class, pagination support, and utility functions for error handling and sending structured r

Downloads

48

Readme

@ahextechnology/sucess-error-responses

Utility package for consistent API responses in Node.js/Express applications.

It supports:

  • Legacy response format (sendResponse, handleError, Status, Pagination)
  • Standardized success/error envelopes (successResponse, errorResponse)
  • Custom application errors (AppError, createErrorCatalog, errorResponseFromError)

Installation

npm install @ahextechnology/sucess-error-responses

Exports

const {
  // Legacy API
  NoResponseError,
  ServerError,
  ClientError,
  Status,
  Pagination,
  handleError,
  sendResponse,

  // Standardized API
  successResponse,
  errorResponse,
  errorResponseFromError,
  SuccessResponse,
  ErrorResponse,
  Meta,
  ErrorDetail,

  // Custom error utilities
  AppError,
  createErrorCatalog,
} = require('@ahextechnology/sucess-error-responses');

Standardized Response Format

Success response shape

{
  "success": true,
  "message": "User fetched successfully",
  "data": { "id": 1, "name": "John" },
  "meta": null,
  "timestamp": "2026-03-23T06:58:26.641Z"
}

Error response shape

{
  "success": false,
  "message": "Validation failed",
  "error": {
    "code": "VALIDATION_ERROR",
    "statusCode": 422,
    "details": [
      { "field": "email", "message": "Email is required" }
    ]
  },
  "timestamp": "2026-03-23T06:58:26.641Z"
}

Usage

1) successResponse

const express = require('express');
const { successResponse } = require('@ahextechnology/sucess-error-responses');

const app = express();

app.get('/user/:id', (req, res) => {
  const user = { id: Number(req.params.id), name: 'John' };
  return successResponse(res, 'User fetched successfully', user);
});

With pagination metadata:

const { successResponse } = require('@ahextechnology/sucess-error-responses');

app.get('/users', (req, res) => {
  const users = [{ id: 1 }, { id: 2 }];
  return successResponse(
    res,
    'Users listed',
    users,
    { page: 1, limit: 10, total: 25 } // meta
  );
});

2) errorResponse

const { errorResponse, ErrorDetail } = require('@ahextechnology/sucess-error-responses');

app.get('/not-found', (req, res) => {
  return errorResponse(res, 'User not found', 'USER_NOT_FOUND', 404);
});

app.get('/validation', (req, res) => {
  const details = [
    new ErrorDetail('email', 'Email is required'),
    new ErrorDetail('password', 'Password must be at least 8 characters'),
  ];
  return errorResponse(res, 'Validation failed', 'VALIDATION_ERROR', 422, details);
});

Masked error example (hide real HTTP status from clients):

return errorResponse(
  res,
  'Database connection failed',
  'DB_CONNECTION_FAILED',
  503,   // real status
  null,
  true,  // maskError
  1001   // body.error.statusCode
);

3) AppError + createErrorCatalog + errorResponseFromError

const {
  createErrorCatalog,
  errorResponseFromError,
} = require('@ahextechnology/sucess-error-responses');

const DB_ERRORS = createErrorCatalog({
  CONNECTION_FAILED: {
    message: 'Database connection failed',
    code: 'DB_CONNECTION_FAILED',
    statusCode: 503,
    errorNumber: 1001,
  },
  RECORD_NOT_FOUND: {
    message: 'Record not found',
    code: 'NOT_FOUND',
    statusCode: 404,
  },
});

app.get('/catalog-error', (req, res) => {
  return errorResponseFromError(res, DB_ERRORS.CONNECTION_FAILED, true);
});

Legacy API (Backward Compatibility)

The original API is still available:

  • sendResponse(req, res, next, items, statusModel, pagination)
  • handleError(err, req, res, next)
  • Status, Pagination
  • NoResponseError, ServerError, ClientError

Example:

const {
  sendResponse,
  Status,
  Pagination,
} = require('@ahextechnology/sucess-error-responses');

app.get('/legacy/items', (req, res, next) => {
  const items = [{ id: 1 }, { id: 2 }];
  const status = new Status(200, 'Success', 'Items fetched successfully');
  const pagination = new Pagination('id', 'asc', 2, 10, 1, false);
  return sendResponse(req, res, next, items, status, pagination);
});

Local Verification

npm test

Publish Checklist (npm)

  1. Update version in package.json (semver).
  2. Confirm package name is correct: @ahextechnology/sucess-error-responses.
  3. Run:
    npm install
    npm test
  4. Login and publish:
    npm login
    npm publish --access public

License

ISC