From 88934dea56e19a440f2ac3e2d9629a2ce559ce57 Mon Sep 17 00:00:00 2001 From: Ame_x Edam Date: Fri, 26 Jan 2024 15:36:34 +0000 Subject: [PATCH 1/2] refactor: "if" on one line --- src/hono-base.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/hono-base.ts b/src/hono-base.ts index d022ba744..4cd3c2935 100644 --- a/src/hono-base.ts +++ b/src/hono-base.ts @@ -48,8 +48,7 @@ const errorHandler = (err: Error, c: Context) => { return err.getResponse() } console.error(err) - const message = 'Internal Server Error' - return c.text(message, 500) + return c.text('Internal Server Error', 500) } type GetPath = (request: Request, options?: { env?: E['Bindings'] }) => string @@ -189,9 +188,7 @@ class Hono< ): Hono> & S, BasePath> { const subApp = this.basePath(path) - if (!app) { - return subApp - } + if (!app) return subApp app.routes.map((r) => { let handler @@ -298,9 +295,7 @@ class Hono< } private handleError(err: unknown, c: Context) { - if (err instanceof Error) { - return this.errorHandler(err, c) - } + if (err instanceof Error) return this.errorHandler(err, c) throw err } @@ -330,9 +325,7 @@ class Hono< let res: ReturnType try { res = matchResult[0][0][0][0](c, async () => {}) - if (!res) { - return this.notFoundHandler(c) - } + if (!res) return this.notFoundHandler(c) } catch (err) { return this.handleError(err, c) } @@ -343,9 +336,7 @@ class Hono< let awaited: Response | void try { awaited = await res - if (!awaited) { - return this.notFoundHandler(c) - } + if (!awaited) return this.notFoundHandler(c) } catch (err) { return this.handleError(err, c) } @@ -363,6 +354,7 @@ class Hono< 'Context is not finalized. You may forget returning Response object or `await next()`' ) } + return context.res } catch (err) { return this.handleError(err, c) From bc24bd33bb3edf167c046e101f19dec0a6de4580 Mon Sep 17 00:00:00 2001 From: Ame_x Edam Date: Fri, 26 Jan 2024 15:37:47 +0000 Subject: [PATCH 2/2] chore: denoify & format --- deno_dist/hono-base.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/deno_dist/hono-base.ts b/deno_dist/hono-base.ts index 1475d46d0..f47b6c8e5 100644 --- a/deno_dist/hono-base.ts +++ b/deno_dist/hono-base.ts @@ -48,8 +48,7 @@ const errorHandler = (err: Error, c: Context) => { return err.getResponse() } console.error(err) - const message = 'Internal Server Error' - return c.text(message, 500) + return c.text('Internal Server Error', 500) } type GetPath = (request: Request, options?: { env?: E['Bindings'] }) => string @@ -189,9 +188,7 @@ class Hono< ): Hono> & S, BasePath> { const subApp = this.basePath(path) - if (!app) { - return subApp - } + if (!app) return subApp app.routes.map((r) => { let handler @@ -298,9 +295,7 @@ class Hono< } private handleError(err: unknown, c: Context) { - if (err instanceof Error) { - return this.errorHandler(err, c) - } + if (err instanceof Error) return this.errorHandler(err, c) throw err } @@ -330,9 +325,7 @@ class Hono< let res: ReturnType try { res = matchResult[0][0][0][0](c, async () => {}) - if (!res) { - return this.notFoundHandler(c) - } + if (!res) return this.notFoundHandler(c) } catch (err) { return this.handleError(err, c) } @@ -343,9 +336,7 @@ class Hono< let awaited: Response | void try { awaited = await res - if (!awaited) { - return this.notFoundHandler(c) - } + if (!awaited) return this.notFoundHandler(c) } catch (err) { return this.handleError(err, c) } @@ -363,6 +354,7 @@ class Hono< 'Context is not finalized. You may forget returning Response object or `await next()`' ) } + return context.res } catch (err) { return this.handleError(err, c)