{"library":"middy-middleware-json-error-handler","title":"Middy JSON Error Handler Middleware","description":"A middleware for the Middy.js Lambda middleware engine that converts thrown errors into structured JSON HTTP responses, compatible with http-errors. Current stable version is 4.0.0 (released 2023-07-26). Follows semantic release, with updates every few months. Key differentiators: automatic JSON serialization, support for http-errors and custom error classes, configurable property omission (stack, name, etc.), and the ability to expose internal errors via the `expose` property even for 5xx responses. Ships TypeScript types.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install middy-middleware-json-error-handler"],"cli":null},"imports":["import JSONErrorHandlerMiddleware from 'middy-middleware-json-error-handler'","const JSONErrorHandlerMiddleware = require('middy-middleware-json-error-handler').default",".use(JSONErrorHandlerMiddleware(options))"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import middy from '@middy/core';\nimport JSONErrorHandlerMiddleware from 'middy-middleware-json-error-handler';\nimport createError from 'http-errors';\n\nconst baseHandler = async (event) => {\n  const search = event.queryStringParameters?.search;\n  if (!search) {\n    throw createError(400, 'Query must include search');\n  }\n  if (search === 'error') {\n    throw createError(500, 'Internal error', { expose: true });\n  }\n  throw new Error('Search not implemented');\n};\n\nconst handler = middy(baseHandler)\n  .use(JSONErrorHandlerMiddleware({ errorPropertiesToOmit: ['stack'] }));\n\nexport { handler };","lang":"typescript","description":"Creates a Middy handler that uses the JSON error handler middleware to return structured JSON errors.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}