middy-middleware-json-error-handler
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -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; |
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16218
18
139
61