@kiyasov/platform-hono 1.1.3 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiyasov/platform-hono",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Nest adapter for Hono",
5
5
  "author": "Islam Kiiasov",
6
6
  "license": "MIT",
@@ -53,11 +53,15 @@ export class HonoAdapter extends AbstractHttpAdapter<
53
53
  private createRouteHandler(routeHandler: HonoHandler) {
54
54
  return async (ctx: Context, next: Next) => {
55
55
  await routeHandler(ctx.req, ctx, next);
56
- const body = ctx.get("body");
57
- return typeof body === "string" ? ctx.text(body) : ctx.json(body);
56
+ return this.send(ctx);
58
57
  };
59
58
  }
60
59
 
60
+ private send(ctx: Context) {
61
+ const body = ctx.get("body");
62
+ return typeof body === "string" ? ctx.text(body) : ctx.json(body);
63
+ }
64
+
61
65
  public get(pathOrHandler: string | HonoHandler, handler?: HonoHandler) {
62
66
  const [routePath, routeHandler] = this.getRouteAndHandler(
63
67
  pathOrHandler,
@@ -149,16 +153,14 @@ export class HonoAdapter extends AbstractHttpAdapter<
149
153
  public setErrorHandler(handler: ErrorHandler) {
150
154
  this.instance.onError(async (err: Error, ctx: Context) => {
151
155
  await handler(err, ctx.req, ctx);
152
- const body = ctx.get("body");
153
- return typeof body === "string" ? ctx.text(body) : ctx.json(body);
156
+ return this.send(ctx);
154
157
  });
155
158
  }
156
159
 
157
160
  public setNotFoundHandler(handler: RequestHandler) {
158
161
  this.instance.notFound(async (ctx: Context) => {
159
162
  await handler(ctx.req, ctx);
160
- const body = ctx.get("body");
161
- return typeof body === "string" ? ctx.text(body) : ctx.json(body);
163
+ return this.send(ctx);
162
164
  });
163
165
  }
164
166