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.

devops
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.

Package uses CommonJS; ESM import is not supported.

const errorFormatter = require('lambda-errors-formatter')

Main function.

errorFormatter.format('message')

Returns status 400.

errorFormatter.badRequest('message')

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 footguns
gotchaThe package outputs error messages as a JSON string inside the 'body' field, not as a parsed object.
gotchaThe 'format' function without a statusCode uses a default of 500; passing a string only gives status 500.
gotchaCORS headers are hardcoded to allow all origins. This may not be suitable for production with sensitive data.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources