@middy/http-error-handler 5.0.0-alpha.0 → 5.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,8 +19,9 @@
19
19
  <a href="https://snyk.io/test/github/middyjs/middy">
20
20
  <img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
21
21
  </a>
22
- <a href="https://lgtm.com/projects/g/middyjs/middy/context:javascript">
23
- <img src="https://img.shields.io/lgtm/grade/javascript/g/middyjs/middy.svg?logo=lgtm&logoWidth=18" alt="Language grade: JavaScript" style="max-width:100%;">
22
+ <a href="https://github.com/middyjs/middy/actions/workflows/sast.yml">
23
+ <img src="https://github.com/middyjs/middy/actions/workflows/sast.yml/badge.svg
24
+ ?branch=main&event=push" alt="CodeQL" style="max-width:100%;">
24
25
  </a>
25
26
  <a href="https://bestpractices.coreinfrastructure.org/projects/5280">
26
27
  <img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
package/index.js CHANGED
@@ -13,9 +13,11 @@ const httpErrorHandlerMiddleware = (opts = {})=>{
13
13
  if (typeof options.logger === 'function') {
14
14
  options.logger(request.error);
15
15
  }
16
+ // Set default expose value, only passes in when there is an override
16
17
  if (request.error.statusCode && request.error.expose === undefined) {
17
18
  request.error.expose = request.error.statusCode < 500;
18
19
  }
20
+ // Non-http error OR expose set to false
19
21
  if (options.fallbackMessage && (!request.error.statusCode || !request.error.expose)) {
20
22
  request.error = {
21
23
  statusCode: 500,
@@ -25,7 +27,7 @@ const httpErrorHandlerMiddleware = (opts = {})=>{
25
27
  }
26
28
  if (request.error.expose) {
27
29
  normalizeHttpResponse(request);
28
- const { statusCode , message , headers } = request.error;
30
+ const { statusCode, message, headers } = request.error;
29
31
  request.response = {
30
32
  ...request.response,
31
33
  statusCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-error-handler",
3
- "version": "5.0.0-alpha.0",
3
+ "version": "5.0.0-alpha.2",
4
4
  "description": "Http error handler middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -10,24 +10,18 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "./index.cjs",
14
13
  "module": "./index.js",
15
14
  "exports": {
16
15
  ".": {
17
16
  "import": {
18
17
  "types": "./index.d.ts",
19
18
  "default": "./index.js"
20
- },
21
- "require": {
22
- "types": "./index.d.ts",
23
- "default": "./index.cjs"
24
19
  }
25
20
  }
26
21
  },
27
22
  "types": "index.d.ts",
28
23
  "files": [
29
24
  "index.js",
30
- "index.cjs",
31
25
  "index.d.ts"
32
26
  ],
33
27
  "scripts": {
@@ -67,12 +61,12 @@
67
61
  "url": "https://github.com/sponsors/willfarrell"
68
62
  },
69
63
  "dependencies": {
70
- "@middy/util": "5.0.0-alpha.0"
64
+ "@middy/util": "5.0.0-alpha.2"
71
65
  },
72
66
  "devDependencies": {
73
- "@middy/core": "5.0.0-alpha.0",
67
+ "@middy/core": "5.0.0-alpha.2",
74
68
  "@types/http-errors": "^2.0.0",
75
- "@types/node": "^18.0.0"
69
+ "@types/node": "^20.0.0"
76
70
  },
77
- "gitHead": "08c35e3dba9efdad0b86666ce206ce302cc65d07"
71
+ "gitHead": "ebce8d5df8783077fa49ba62ee9be20e8486a7f1"
78
72
  }
package/index.cjs DELETED
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(module, "exports", {
6
- enumerable: true,
7
- get: ()=>_default
8
- });
9
- const _util = require("@middy/util");
10
- const defaults = {
11
- logger: console.error,
12
- fallbackMessage: null
13
- };
14
- const httpErrorHandlerMiddleware = (opts = {})=>{
15
- const options = {
16
- ...defaults,
17
- ...opts
18
- };
19
- const httpErrorHandlerMiddlewareOnError = async (request)=>{
20
- if (request.response !== undefined) return;
21
- if (typeof options.logger === 'function') {
22
- options.logger(request.error);
23
- }
24
- if (request.error.statusCode && request.error.expose === undefined) {
25
- request.error.expose = request.error.statusCode < 500;
26
- }
27
- if (options.fallbackMessage && (!request.error.statusCode || !request.error.expose)) {
28
- request.error = {
29
- statusCode: 500,
30
- message: options.fallbackMessage,
31
- expose: true
32
- };
33
- }
34
- if (request.error.expose) {
35
- (0, _util.normalizeHttpResponse)(request);
36
- const { statusCode , message , headers } = request.error;
37
- request.response = {
38
- ...request.response,
39
- statusCode,
40
- body: message,
41
- headers: {
42
- ...headers,
43
- ...request.response.headers,
44
- 'Content-Type': typeof (0, _util.jsonSafeParse)(message) === 'string' ? 'text/plain' : 'application/json'
45
- }
46
- };
47
- }
48
- };
49
- return {
50
- onError: httpErrorHandlerMiddlewareOnError
51
- };
52
- };
53
- const _default = httpErrorHandlerMiddleware;
54
-