Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

middy-middleware-json-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy-middleware-json-error-handler

A middy JSON error handler middleware.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.6K
decreased by-15.26%
Maintainers
1
Weekly downloads
 
Created
Source

middy-middleware-json-error-handler

npm version downloads open issues FOSSA Status debug build status codecov dependency status devDependency status semantic release Gitter

A middy middleware that returns errors as http errors, compatible with http-errors.

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install middy-middleware-json-error-handler --save

Documentation

There is additional documentation.

Usage

import middy from 'middy'
import JSONErrorHandlerMiddleware from 'middy-middleware-json-error-handler'
import createHttpError from 'http-errors'
import { APIGatewayEvent } from 'aws-lambda'

// This is your AWS handler
async function helloWorld (event: APIGatewayEvent) {
  if (event.queryStringParameters?.search == null) {
    // If you throw an error with status code, the error will be returned as stringified JSON.
    // Only the stack will be omitted.
    throw createHttpError(400, 'Query has to include a search')
  }

  // If you throw an error with no status code, only a generic message will be shown to the user
  // instead of the full error
  throw new Error('Search is not implemented yet')
}

// Let's "middyfy" our handler, then we will be able to attach middlewares to it
export const handler = middy(helloWorld)
  .use(JSONErrorHandlerMiddleware()) // This middleware is needed do handle the errors thrown by the JWTAuthMiddleware

Keywords

FAQs

Package last updated on 10 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc