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

@keboola/middy-error-logger

Package Overview
Dependencies
Maintainers
5
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@keboola/middy-error-logger

Error logger middleware for Middy

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25
increased by212.5%
Maintainers
5
Weekly downloads
 
Created
Source

Error Logger Middleware for Middy

Build Status

Errors logging middleware for Middy.

The middleware catches thrown exceptions and rejected promises and logs them comprehensibly to the console. All logs are enriched with event and context.

It works with http-errors module and creates a proper HTTP response for them using the message and the status code.

Usage

import createError from 'http-errors';
import middy from 'middy';
import errorLogger from '@keboola/middy-error-logger';

export const handler = middy(() => {
  throw new createError.UnprocessableEntity();
});

handler
  .use(errorLogger());

This sample code writes such a stringified json to the console:

{
  "message": "Unprocessable Entity",
  "statusCode": 422,
  "stack": [
    "UnprocessableEntityError: Unprocessable Entity",
    "at Function._callee$ (/var/task/src/lambda.js:6:19)",
    "at tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:62:40)",
    "..."
  ],
  "event": {
    "resource": "/",
    "httpMethod": "GET",
    "queryStringParameters": null,
    "body": null
  },
  "context": {
    "sourceIp": "214.178.123.91",
    "userAgent": "Paw/3.1.7 (Macintosh; OS X/10.14.0) GCDHTTPRequest"
  },
  "awsRequestId": "ab022f5a-d3ad-11e8-89f6-89a425b4ca0a"
}

And return this message to the request response:

{
  "errorMessage": "Unprocessable Entity",
  "errorCode": 422,
  "requestId": "ab022f5a-d3ad-11e8-89f6-89a425b4ca0a"
}

If the error is not an instance from http-errors, the error message in the response is replaced with "Internal Error." and the status code is set to 500.

FAQs

Package last updated on 08 Apr 2019

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