Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: "if" on one line and deletion of unneeded variables #2093

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 6 additions & 14 deletions deno_dist/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<E extends Env> = (request: Request, options?: { env?: E['Bindings'] }) => string
Expand Down Expand Up @@ -189,9 +188,7 @@ class Hono<
): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath> {
const subApp = this.basePath(path)

if (!app) {
return subApp
}
if (!app) return subApp

app.routes.map((r) => {
let handler
Expand Down Expand Up @@ -298,9 +295,7 @@ class Hono<
}

private handleError(err: unknown, c: Context<E>) {
if (err instanceof Error) {
return this.errorHandler(err, c)
}
if (err instanceof Error) return this.errorHandler(err, c)
throw err
}

Expand Down Expand Up @@ -330,9 +325,7 @@ class Hono<
let res: ReturnType<H>
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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
20 changes: 6 additions & 14 deletions src/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<E extends Env> = (request: Request, options?: { env?: E['Bindings'] }) => string
Expand Down Expand Up @@ -189,9 +188,7 @@ class Hono<
): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath> {
const subApp = this.basePath(path)

if (!app) {
return subApp
}
if (!app) return subApp

app.routes.map((r) => {
let handler
Expand Down Expand Up @@ -298,9 +295,7 @@ class Hono<
}

private handleError(err: unknown, c: Context<E>) {
if (err instanceof Error) {
return this.errorHandler(err, c)
}
if (err instanceof Error) return this.errorHandler(err, c)
throw err
}

Expand Down Expand Up @@ -330,9 +325,7 @@ class Hono<
let res: ReturnType<H>
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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down