@middy/http-error-handler 7.1.2 → 7.1.4

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
@@ -30,10 +30,23 @@
30
30
  <p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/http-error-handler">https://middy.js.org/docs/middlewares/http-error-handler</a></p>
31
31
  </div>
32
32
 
33
- ## License
33
+ ## Install
34
+
35
+ ```bash
36
+ npm install --save @middy/http-error-handler
37
+ ```
38
+
39
+
40
+ ## Documentation and examples
41
+
42
+ For documentation and examples, refer to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org/docs/middlewares/http-error-handler).
34
43
 
35
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2026 [will Farrell](https://github.com/willfarrell), [Luciano Mammino](https://github.com/lmammino), and [Middy contributors](https://github.com/middyjs/middy/graphs/contributors).
36
44
 
37
- <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
38
- <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
39
- </a>
45
+ ## Contributing
46
+
47
+ Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
48
+
49
+
50
+ ## License
51
+
52
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2026 [will Farrell](https://github.com/willfarrell), [Luciano Mammino](https://github.com/lmammino), and [Middy contributors](https://github.com/middyjs/middy/graphs/contributors).
package/index.d.ts CHANGED
@@ -3,10 +3,12 @@
3
3
  import type middy from "@middy/core";
4
4
 
5
5
  export interface Options {
6
- logger?: ((error: any) => void) | boolean;
6
+ logger?: ((error: Error) => void) | boolean;
7
7
  fallbackMessage?: string;
8
8
  }
9
9
 
10
- declare function httpErrorHandler(options?: Options): middy.MiddlewareObj;
10
+ declare function httpErrorHandler(
11
+ options?: Options,
12
+ ): middy.MiddlewareObj<unknown, unknown, Error>;
11
13
 
12
14
  export default httpErrorHandler;
package/index.js CHANGED
@@ -10,14 +10,17 @@ const defaults = {
10
10
  const httpErrorHandlerMiddleware = (opts = {}) => {
11
11
  const options = { ...defaults, ...opts };
12
12
 
13
- const httpErrorHandlerMiddlewareOnError = async (request) => {
14
- if (request.response !== undefined) return;
13
+ const httpErrorHandlerMiddlewareOnError = (request) => {
14
+ if (typeof request.response !== "undefined") return;
15
15
  if (typeof options.logger === "function") {
16
16
  options.logger(request.error);
17
17
  }
18
18
 
19
19
  // Set default expose value, only passes in when there is an override
20
- if (request.error.statusCode && request.error.expose === undefined) {
20
+ if (
21
+ request.error.statusCode &&
22
+ typeof request.error.expose === "undefined"
23
+ ) {
21
24
  request.error.expose = request.error.statusCode < 500;
22
25
  }
23
26
 
@@ -34,14 +37,10 @@ const httpErrorHandlerMiddleware = (opts = {}) => {
34
37
  normalizeHttpResponse(request);
35
38
  const { statusCode, message, headers } = request.error;
36
39
 
37
- request.response = {
38
- ...request.response,
39
- statusCode,
40
- headers: {
41
- ...request.response.headers,
42
- ...headers,
43
- },
44
- };
40
+ request.response.statusCode = statusCode;
41
+ if (headers) {
42
+ Object.assign(request.response.headers, headers);
43
+ }
45
44
 
46
45
  if (message) {
47
46
  const headerContentType =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-error-handler",
3
- "version": "7.1.2",
3
+ "version": "7.1.4",
4
4
  "description": "HTTP error handler middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -66,12 +66,11 @@
66
66
  "url": "https://github.com/sponsors/willfarrell"
67
67
  },
68
68
  "dependencies": {
69
- "@middy/util": "7.1.2"
69
+ "@middy/util": "7.1.4"
70
70
  },
71
71
  "devDependencies": {
72
- "@middy/core": "7.1.2",
72
+ "@middy/core": "7.1.4",
73
73
  "@types/http-errors": "^2.0.0",
74
74
  "@types/node": "^22.0.0"
75
- },
76
- "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
75
+ }
77
76
  }