Registry / devops / lambda-errors-formatter

lambda-errors-formatter

JSON →
library0.5.0jsnpmunverified

A utility for formatting AWS Lambda error responses into a consistent JSON structure with HTTP status codes, CORS headers, and serialized error messages. Version 0.5.0 is the latest stable release. It provides a simple API with helper methods for common HTTP errors (bad request, unauthorized, forbidden, not found, conflict, internal server error). Compared to alternatives like @middy/http-error-handler, this package is lighter and focuses on formatting errors rather than handling Lambda lifecycle. It is ESM-only? No, it uses CommonJS require. No recent updates; appears to be in maintenance mode.

npm install lambda-errors-formatter
INSTALL
IMPORT
SIG · LAMBDA-ERRORS-FORM
L
lambda-errors-formatter
devopsjavascriptv0.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

errorFormatter
const errorFormatter = require('lambda-errors-formatter')
import errorFormatter from 'lambda-errors-formatter'
Package uses CommonJS; ESM import is not supported.
format
errorFormatter.format('message')
Main function.
badRequest
errorFormatter.badRequest('message')
Returns status 400.

Shows how to import the package and format errors with default status, custom status code, and named helper function.

const errorFormatter = require('lambda-errors-formatter'); // Format a simple error message (status 500) const error500 = errorFormatter.format('Something went wrong'); console.log(error500); // Output: // { // statusCode: 500, // body: "{\"message\":\"Something went wrong\"}", // headers: { 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json' } // } // Format with custom status code const error400 = errorFormatter.formatCode(400, 'Bad input'); console.log(error400); // Use named helper for bad request const badReq = errorFormatter.badRequest('Invalid data'); console.log(badReq);
Debug
Known issues
gotchaThe package outputs error messages as a JSON string inside the 'body' field, not as a parsed object.
fix
Parse the body if you need an object: JSON.parse(response.body)
affects: >=0
gotchaThe 'format' function without a statusCode uses a default of 500; passing a string only gives status 500.
fix
Use formatCode(statusCode, message) or named helpers for explicit codes.
affects: >=0
gotchaCORS headers are hardcoded to allow all origins. This may not be suitable for production with sensitive data.
fix
Modify the headers in the response before returning, or use a custom response formatter.
affects: >=0
Errors
Common errors & fixes
TypeError: errorFormatter.format is not a function
Importing the package incorrectly, e.g., using default ESM import.
fix
Use CommonJS require: const errorFormatter = require('lambda-errors-formatter');
Cannot find module 'lambda-errors-formatter'
Package not installed or not in node_modules.
fix
Run: npm install lambda-errors-formatter --save
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
Resources