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

@mimik/response-helper

v4.0.10

Published

HTTP response helper for mimik microservices

Readme

responseHelper

Example

// Default import
import responseHelper from '@mimik/response-helper';

Example

// Named imports
import { ERROR_CODE, RESPONSE_CODE, sendError, sendResult, getRichError, cleanObj, getErrorStatusCode } from '@mimik/response-helper';

responseHelper~cleanObj(mObj, properties) ⇒ object

Clean a mongoose object

Kind: inner method of responseHelper
Returns: object - The cleaned Mongoose object (or array), or the original value if not an object/array.
Category: sync

| Param | Type | Description | | --- | --- | --- | | mObj | object | Mongoose object to clean. If null, not an array, or not an object, returns mObj as-is. | | properties | array | Properties to remove from the object. Top level only. If null or not an array, the default ['_id', '__v'] is used. |

responseHelper~sendError(error, response, otherErrorStatusCode, swaggerOptions, logLevel, parameters) ⇒ void

The response body contains either error or info, never both:

  • If the error param is an Error instance, the body includes an error field.
  • Otherwise, the body includes an info field with the raw value.
{
  "statusCode": <HTTP code>,
  "title": "<HTTP title>",
  "message": "error.message or 'no message' if not present",
  "error": "<present when error is an Error instance>",
  "info": "<present when error is NOT an Error instance>"
}

Swagger options:

{
  "swagger": {
    "method": "<request method>",
    "path": "<request path>",
    "operationId": "<operation id for the route>"
  },
  "correlationId": "<value from request headers if present; otherwise a UUID>"
}

Parameters (optional):

{
  "rfc": "use RFC 7807 format when set to '7807' (may also be present on the error itself)",
  "headers": { "<headerName>": "<value>", ... } // extra headers to add to the response
}

If a response with statusCode >= 500 is sent and logging is enabled but not explicitly set, an error-level log is emitted; otherwise a warn-level log is used.

Kind: inner method of responseHelper
Category: sync
Requires: module:@mimik/sumologic-winston-logger

| Param | Type | Description | | --- | --- | --- | | error | Error | string | The error to include in the response. | | response | object | The HTTP response object. | | otherErrorStatusCode | number | Status code that overrides error.statusCode for the response. | | swaggerOptions | object | Object containing Swagger values used to set up the error. | | logLevel | boolean | string | Controls logging. If true, no log is written. If a valid level (e.g., 'error', 'warn', 'info'), uses that level. If null/undefined/invalid, defaults to error for 500+ or warn otherwise. | | parameters | object | Parameters to add or configure the response |

responseHelper~sendResult(result, statusCode, response, swaggerOptions, logLevel, parameters) ⇒ void

If result contains a data field, it is sent as-is (after optional cleanup). Otherwise, the payload is wrapped under a data property.

Parameters (optional):

{
  "noTouch": true // send `result` exactly as provided (no wrapping/cleanup). If Buffer, writes raw bytes.
  "headers": { "<headerName>": "<value>", ... }, // extra headers to add
  "cleanUp": ["propA", "propB"] // top-level properties to remove from the object(s) in `data`
}

Kind: inner method of responseHelper
Category: sync
Requires: module:@mimik/sumologic-winston-logger, module:@mimik/lib-filters

| Param | Type | Description | | --- | --- | --- | | result | object | Buffer | The result to send. | | statusCode | number | HTTP status code to send. | | response | object | The HTTP response object. | | swaggerOptions | object | Object containing values for logging (see sendError). | | logLevel | string | boolean | Controls logging. If true, no log is written. If a valid level, uses that level. If null/undefined/invalid, defaults to info. | | parameters | object | Parameters to add or configure the response. |

responseHelper~getErrorStatusCode(type, error) ⇒ number

Get the HTTP status code for a given error type.

Kind: inner method of responseHelper
Returns: number - The HTTP status code.
Category: sync

| Param | Type | Description | | --- | --- | --- | | type | string | Error type name. Valid values: System (500), Conflict (409), Forbidden (403), MultiStatus (207), NoContent (204), NotAllowed (405), NotFound (404), NotImplemented (501), Parameter / ParameterError (400), Partial (206), UnAuthorized (401), Unprocessable (422). Null or unrecognized values default to 500. | | error | object | Error object. Used as a fallback when type is unrecognized: if error.name is 'EntryError' returns 409, if error.name is 'CastError' returns 404 (when error.kind is 'ObjectId') or 400 (otherwise). |

responseHelper~getRichError(val, message, info, origErr, logLevel, correlationId) ⇒ Error

Create a rich error.

Kind: inner method of responseHelper
Returns: Error - The rich error instance.

{
  "statusCode": "<HTTP Code>",
  "title": "<HTTP title>",
  "name": "<error name>",
  "info": "<additional info>",
  "cause": "<encapsulated error, if any>",
  "message": "<error message>"
}

Category: sync
Requires: module:@mimik/sumologic-winston-logger

| Param | Type | Description | | --- | --- | --- | | val | string | number | If a string, the error name; if a number, the HTTP status code (e.g., 400, 500). Invalid values fall back to 500. | | message | string | Message to associate with the error. | | info | object | Arbitrary info to associate with the error. | | origErr | * | Error to encapsulate as the cause. | | logLevel | string | boolean | Logging behavior. If false, logs at 'error'. If a valid level, uses that level. If true or null/undefined, no log is written. | | correlationId | string | Correlation ID to add to the log when logging is enabled. |