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 - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

lib/interfaces/IErrorWithExpose.d.ts

1

lib/JSONErrorHandlerMiddleware.d.ts

@@ -25,4 +25,5 @@ import { Context as LambdaContext } from 'aws-lambda/handler';

onError: (request: Request) => Promise<void>;
private shouldExposeError;
}
declare const _default: typeof JSONErrorHandlerMiddleware.create;
export default _default;

8

lib/JSONErrorHandlerMiddleware.js

@@ -10,2 +10,3 @@ "use strict";

var debug_1 = tslib_1.__importDefault(require("debug"));
var IErrorWithExpose_1 = require("./interfaces/IErrorWithExpose");
var IErrorWithStatusCode_1 = require("./interfaces/IErrorWithStatusCode");

@@ -18,3 +19,3 @@ var omit_1 = require("./helpers/omit");

function JSONErrorHandlerMiddleware(_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.errorPropertiesToOmit, errorPropertiesToOmit = _c === void 0 ? ['stack'] : _c;
var _b = _a === void 0 ? {} : _a, _c = _b.errorPropertiesToOmit, errorPropertiesToOmit = _c === void 0 ? ['stack', 'expose'] : _c;
var _this = this;

@@ -25,3 +26,3 @@ this.onError = function (request) { return tslib_1.__awaiter(_this, void 0, void 0, function () {

error = request.error;
if ((0, IErrorWithStatusCode_1.isErrorWithStatusCode)(error) && error.statusCode < 500) {
if ((0, IErrorWithStatusCode_1.isErrorWithStatusCode)(error) && this.shouldExposeError(error)) {
this.logger("Responding with full error as statusCode is ".concat(error.statusCode));

@@ -52,2 +53,5 @@ request.response = {

};
JSONErrorHandlerMiddleware.prototype.shouldExposeError = function (error) {
return (0, IErrorWithExpose_1.isErrorWithExpose)(error) ? error.expose : error.statusCode < 500;
};
return JSONErrorHandlerMiddleware;

@@ -54,0 +58,0 @@ }());

{
"name": "middy-middleware-json-error-handler",
"version": "3.1.0",
"version": "4.0.0",
"description": "A middy JSON error handler middleware.",

@@ -5,0 +5,0 @@ "homepage": "",

@@ -41,2 +41,8 @@ # middy-middleware-json-error-handler

if (event.queryStringParameters?.search === 'error') {
// If you throw an error with status code greater than 500 and specify in options that the error
// must be exposed, then the error will be returned as stringified JSON
throw createHttpError(500, 'Something went wrong', { expose: true })
}
// If you throw an error with no status code, only a generic message will be shown to the user

@@ -51,2 +57,3 @@ // instead of the full error

}
// Let's "middyfy" our handler, then we will be able to attach middlewares to it (options parameter is optional)

@@ -53,0 +60,0 @@ export const handler = middy(helloWorld)

Sorry, the diff of this file is not supported yet

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