JSPM

@lambda-middleware/http-error-handler

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1326
  • Score
    100M100P100Q121002F
  • License MIT

An error handler middleware for AWS http lambda functions.

Package Exports

  • @lambda-middleware/http-error-handler

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@lambda-middleware/http-error-handler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@lambda-middleware/http-error-handler

npm version downloads open issues debug build status codecov dependency status devDependency status

An error handler middleware for AWS http lambda functions, compatible with http-errors.

Lambda middleware

This middleware is part of the lambda middleware series. It can be used independently.

Usage

import { errorHandler } from "@lambda-middleware/errorHandler";
import { APIGatewayEvent, APIGatewayProxyResult } from "aws-lambda";
import createHttpError from "http-errors";

// This is your AWS handler
async function helloWorld(
  event: APIGatewayEvent
): Promise<APIGatewayProxyResult> {
  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");
}

// Wrap the handler with the middleware
export const handler = errorHandler()(helloWorld);