hono 2.7.6 → 2.7.7

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.
@@ -22,7 +22,7 @@ __export(compose_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(compose_exports);
24
24
  var import_context = require("./context");
25
- const compose = (middleware, onNotFound, onError) => {
25
+ const compose = (middleware, onError, onNotFound) => {
26
26
  const middlewareLength = middleware.length;
27
27
  return (context, next) => {
28
28
  let index = -1;
package/dist/cjs/hono.js CHANGED
@@ -34,6 +34,14 @@ function defineDynamicClass() {
34
34
  return class {
35
35
  };
36
36
  }
37
+ const notFoundHandler = (c) => {
38
+ return c.text("404 Not Found", 404);
39
+ };
40
+ const errorHandler = (err, c) => {
41
+ console.trace(err);
42
+ const message = "Internal Server Error";
43
+ return c.text(message, 500);
44
+ };
37
45
  class Hono extends defineDynamicClass() {
38
46
  constructor(init = {}) {
39
47
  super();
@@ -44,14 +52,8 @@ class Hono extends defineDynamicClass() {
44
52
  this._tempPath = "";
45
53
  this.path = "/";
46
54
  this.routes = [];
47
- this.notFoundHandler = (c) => {
48
- return c.text("404 Not Found", 404);
49
- };
50
- this.errorHandler = (err, c) => {
51
- console.trace(err);
52
- const message = "Internal Server Error";
53
- return c.text(message, 500);
54
- };
55
+ this.notFoundHandler = notFoundHandler;
56
+ this.errorHandler = errorHandler;
55
57
  this.handleEvent = (event) => {
56
58
  return this.dispatch(event.request, event);
57
59
  };
@@ -85,7 +87,8 @@ class Hono extends defineDynamicClass() {
85
87
  this._tempPath = path;
86
88
  if (app) {
87
89
  app.routes.map((r) => {
88
- this.addRoute(r.method, r.path, r.handler);
90
+ const handler = app.errorHandler === errorHandler ? r.handler : async (...args) => (await (0, import_compose.compose)([r.handler], app.errorHandler)(...args)).res;
91
+ this.addRoute(r.method, r.path, handler);
89
92
  });
90
93
  this._tempPath = "";
91
94
  }
@@ -178,7 +181,7 @@ class Hono extends defineDynamicClass() {
178
181
  })();
179
182
  }
180
183
  const handlers = result ? result.handlers : [this.notFoundHandler];
181
- const composed = (0, import_compose.compose)(handlers, this.notFoundHandler, this.errorHandler);
184
+ const composed = (0, import_compose.compose)(handlers, this.errorHandler, this.notFoundHandler);
182
185
  return (async () => {
183
186
  try {
184
187
  const tmp = composed(c);
package/dist/compose.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/compose.ts
2
2
  import { Context } from "./context.js";
3
- var compose = (middleware, onNotFound, onError) => {
3
+ var compose = (middleware, onError, onNotFound) => {
4
4
  const middlewareLength = middleware.length;
5
5
  return (context, next) => {
6
6
  let index = -1;
package/dist/hono.js CHANGED
@@ -12,6 +12,14 @@ function defineDynamicClass() {
12
12
  return class {
13
13
  };
14
14
  }
15
+ var notFoundHandler = (c) => {
16
+ return c.text("404 Not Found", 404);
17
+ };
18
+ var errorHandler = (err, c) => {
19
+ console.trace(err);
20
+ const message = "Internal Server Error";
21
+ return c.text(message, 500);
22
+ };
15
23
  var Hono = class extends defineDynamicClass() {
16
24
  constructor(init = {}) {
17
25
  super();
@@ -22,14 +30,8 @@ var Hono = class extends defineDynamicClass() {
22
30
  this._tempPath = "";
23
31
  this.path = "/";
24
32
  this.routes = [];
25
- this.notFoundHandler = (c) => {
26
- return c.text("404 Not Found", 404);
27
- };
28
- this.errorHandler = (err, c) => {
29
- console.trace(err);
30
- const message = "Internal Server Error";
31
- return c.text(message, 500);
32
- };
33
+ this.notFoundHandler = notFoundHandler;
34
+ this.errorHandler = errorHandler;
33
35
  this.handleEvent = (event) => {
34
36
  return this.dispatch(event.request, event);
35
37
  };
@@ -63,7 +65,8 @@ var Hono = class extends defineDynamicClass() {
63
65
  this._tempPath = path;
64
66
  if (app) {
65
67
  app.routes.map((r) => {
66
- this.addRoute(r.method, r.path, r.handler);
68
+ const handler = app.errorHandler === errorHandler ? r.handler : async (...args) => (await compose([r.handler], app.errorHandler)(...args)).res;
69
+ this.addRoute(r.method, r.path, handler);
67
70
  });
68
71
  this._tempPath = "";
69
72
  }
@@ -156,7 +159,7 @@ var Hono = class extends defineDynamicClass() {
156
159
  })();
157
160
  }
158
161
  const handlers = result ? result.handlers : [this.notFoundHandler];
159
- const composed = compose(handlers, this.notFoundHandler, this.errorHandler);
162
+ const composed = compose(handlers, this.errorHandler, this.notFoundHandler);
160
163
  return (async () => {
161
164
  try {
162
165
  const tmp = composed(c);
@@ -3,5 +3,5 @@ interface ComposeContext {
3
3
  finalized: boolean;
4
4
  res: unknown;
5
5
  }
6
- export declare const compose: <C extends ComposeContext, E extends Partial<Environment> = Environment>(middleware: Function[], onNotFound?: NotFoundHandler<E> | undefined, onError?: ErrorHandler<E> | undefined) => (context: C, next?: Function) => C | Promise<C>;
6
+ export declare const compose: <C extends ComposeContext, E extends Partial<Environment> = Environment>(middleware: Function[], onError?: ErrorHandler<E> | undefined, onNotFound?: NotFoundHandler<E> | undefined) => (context: C, next?: Function) => C | Promise<C>;
7
7
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "2.7.6",
3
+ "version": "2.7.7",
4
4
  "description": "Ultrafast web framework for Cloudflare Workers, Deno, and Bun.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",